Shoutbox

Visual C++ 6.0 DLLs - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Visual C++ 6.0 DLLs (/showthread.php?tid=77668)

Visual C++ 6.0 DLLs by Spunky on 09-21-2007 at 08:12 PM

I'm trying to make a DLL, but I keep getting "Cannot find entry point <function name> in <dllname>" errors. I've followed instructions from various website, but they all cause the same errors.

Can sombody zip up an example project for me so I can see where I'm going wrong?


RE: Visual C++ 6.0 DLLs by ShawnZ on 09-21-2007 at 08:16 PM

what dll? one of yours or a system one?


RE: Visual C++ 6.0 DLLs by Spunky on 09-21-2007 at 08:18 PM

I'm trying to make one of my own... I've made the .cpp, h and def files and followed the instructions given on website. The DLL makes ok, but I can't call it from within VB


RE: Visual C++ 6.0 DLLs by vikke on 09-21-2007 at 08:32 PM

Are you sure your exported functions are in the def file?
They should be, then compile and copy to the same directory as your VB exe.


RE: Visual C++ 6.0 DLLs by Spunky on 09-21-2007 at 08:33 PM

Yeah, they are definatley exported... I've seen a few sites say that I should do it


RE: Visual C++ 6.0 DLLs by vikke on 09-22-2007 at 07:21 AM

Hmm.. They may be mangled by your compiler. To find out, download dependencywalker from www.dependencywalker.com, and open your DLL.

More information of name mangling here: http://en.wikipedia.org/wiki/Name_mangling


RE: Visual C++ 6.0 DLLs by Spunky on 09-22-2007 at 05:35 PM

quote:
Originally posted by vikke
Hmm.. They may be mangled by your compiler. To find out, download dependencywalker from www.dependencywalker.com, and open your DLL.

I checked it out in Dependency Walker and it appears to be ok...

Still notworking though =/

RE: Visual C++ 6.0 DLLs by vikke on 09-22-2007 at 05:50 PM

It is mangled. Click F10 in Dependency Walker to unmangle all function names.
If it wouldn't be mangled it would be:


RE: Visual C++ 6.0 DLLs by Mnjul on 09-22-2007 at 06:47 PM

Does your DLL has a DllMain function?


RE: Visual C++ 6.0 DLLs by Spunky on 09-22-2007 at 08:34 PM

code:
BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
    }
    return TRUE;
}

RE: Visual C++ 6.0 DLLs by vikke on 09-22-2007 at 09:42 PM

Disable name mangling and it will work. This has nothing to do with DllMain. :)


RE: Visual C++ 6.0 DLLs by Spunky on 09-23-2007 at 12:23 AM

quote:
Originally posted by vikke
It is mangled. Click F10 in Dependency Walker to unmangle all function names

That screenshot is after I'd told it to "undecorate functions" which is what F10 does... Do I have to do something differently?
RE: Visual C++ 6.0 DLLs by vikke on 09-23-2007 at 06:02 AM

Dependency Walker does undecorate these functions (for viewing only). The DLL is not changed, and you have to change your compiler options so it won't decorate your export functions.


RE: Visual C++ 6.0 DLLs by TheSteve on 09-24-2007 at 02:01 AM

Your function should be declared something like this

code:
int WINAPI sum (int n1, int n2)
{
    return n1+n2;
}

Do not use any form of C++ style dll exporting ( DECLSPEC_EXPORT ) as this is for C++ only. If you want to use the function in VB, the function needs to be exported by name only.

in your def file, you should have something like
code:
LIBRARY "functions"
DESCRIPTION "Some description here"
EXPORTS
    ;Explicit exports go here
    sum

If this still doesn't work, make sure that your def file has the same name as the project.
RE: Visual C++ 6.0 DLLs by RaceProUK on 09-24-2007 at 10:29 PM

You can use delcspec(dllexport), so long as you also use extern "C". extern "C" disables name mangling for that function.


RE: Visual C++ 6.0 DLLs by Spunky on 09-24-2007 at 11:09 PM

Ok, I've fixed it now. I needed to re-add the def file once I opened my workspace so I think it was including the file for some reason... Works in VB now at least. All I have to do now is learn C++ :tongue:


RE: RE: Visual C++ 6.0 DLLs by TheSteve on 09-25-2007 at 01:09 AM

quote:
Originally posted by RaceProUK
You can use delcspec(dllexport), so long as you also use extern "C". extern "C" disables name mangling for that function.

The trouble with using __declspec(dllexport) with extern "C" is that the function must be __cdecl in order for the symbol to export without any decoration. Why is this a problem? VB requires dll import functions to be __stdcall
RE: Visual C++ 6.0 DLLs by RaceProUK on 09-27-2007 at 07:54 PM

I always thought extern "C" turned off the decoration completely. After all, __stdcall is merely a calling convention.


RE: RE: RE: Visual C++ 6.0 DLLs by Verte on 09-28-2007 at 03:12 AM

quote:
Originally posted by TheStevethe function must be __cdecl in order for the symbol to export without any decoration.


I don't see why. You can write C programs that export functions with __stdcall calling conventions.