This has been discussed in parts on many places, but it still wont work for me.
I have a dll compiled from delphi source, which exports one function under two names, inspecting the dll using
>> dumpbin /EXPORTS MyLibrary.dll
i get the following output:
...
17 3 00070A88 MyFunction
...
46 24 00070A88 _MyFunction@48
...
so i created a file called MyLibrary.def with the following content:
EXPORTS
MyFunction
_MyFunction@48
And generated an import library using
>> lib /def:MyLibrary.def /OUT:MyLibrary.lib /MACHINE:x86
Inspecting the new lib-file with dumpbin i see the following:
...
_MyFunction
...
__MyFunction@48
...
So somehow the lib application added one underscore in front of the function name. (why?)
Then i try to use this function in a c++ program, compiling with Microsoft Visual Studio C++ 2010 Express (using the lib file):
// MyLibrary.h
# define DllImport(Type) __declspec (dllimport) Type __stdcall
extern "C" DllImport(void)MyFunction(...);
// main.cpp
#import "MyLibrary.h"
...
MyFunction(....);
...
This should now work, as far as i could find out, but i get the following linker error:
... error LNK2001: Unresolved external sympol "__imp__MyFunction@48".
I don't understand why this goes wrong (i dont realy understand how the whole thing works ...) but i tried two more things.
- Renamed my function in MyLibrary.h and main.h from MyFunction to _MyFunction
- Result: it works! But why? I dont want to rely on this, since something is obviously wrong.
- Renamed my function back to MyFunction and removed the underscore in the def-File, generated the lib file again and tried to compile
- Result: compilation succeeds, but when starting the program i get
MyApp - Entry Point Not Found
---------------------------
The procedure entry point MyFunction@48 could not be located
in the dynamic link library MyLibrary.dll.
I think one needs a deeper understanding of the inner working of the lib tool and the linker, but i couldn't find any information about this so far.