Archived

This topic is now archived and is closed to further replies.

CommanderXXL

Functions from DLL not found

Recommended Posts

I have a little problem with my DLL Subsystem i defined 3 functions in the DLL with which i want my main programm to comunicate: extern "C" { __declspec(dllexport) unsigned short __cdecl GetDLLVersion(void) {...} __declspec(dllexport) void* __cdecl GetInterface(CEventManager *MyEventManager) {...} __declspec(dllexport) EInterfaceType __cdecl GetInterfaceType(void) {...} } Then i did set my Project Defaults of the DLL to "DLL" in VS.NET. And now i try to import these functions in my Mainprogramm with these calls: typedef unsigned short (__cdecl * funcDllGetVersion)(void); typedef void* (__cdecl * funcDllGetInterface)(CEventManager *MyEventManager); typedef EInterfaceType (__cdecl * funcDllGetInterfaceType)(void); DllGetVersion = reinterpret_cast GetProcAddress(hDLL,"GetDLLVersion")); ... But i don''t get anyone of the functions, i have always a NULL in my function pointers. What did i do wrong? Are there any additional settings in the project settings for the DLL. Maybe there is a programm with which i can see the function names in the DLL. Thanks for Help. ---------------------------- By CommanderXXL Commander@bredlmuc.de ----------------------------

Share this post


Link to post
Share on other sites

Use Dependency Walker ("Depends" in the Visual Studio Tools folder, also comes with the Platform SDK) on your DLL to find out exactly what the symbols have been exported as.

Try using a .DEF file to prevent any name mangling of the exports.

My guess is the exports will either be full decorated C++ names (even though you''ve used cdecl) or C *linker* names (a single underscore before the name, e.g. "_GetDLLVersion").

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
I tried it now, my function names are exactly what i thought them to be. "GetDLLVersion" "GetInterface"...
No Underscores, no C++ Names. Why does the GetProcAddress function always return NULL?



----------------------------
By CommanderXXL
Commander@bredlmuc.de
----------------------------

Share this post


Link to post
Share on other sites
Your example shows that you''ve typedefed the function pointers but doesn''t show where you''ve declared variables of that type. I assume that someplace you have declared "funcDllGetVersion DllGetVersion"?

Share this post


Link to post
Share on other sites
As the others have said, it''s likely the DLL didn''t load.

When you run a program in the debugger it''ll be run from the Debug\ folder so if the DLL isn''t in there, OR the version of the DLL in your debug folder is older , GetProcAddress will fail.

[Assuming MSVC]
- Put a breakpoint on the line with GetProcAddress().

- Press F5 to run the app.

- When it stops at the breakpoint, press F10 to step over.

- In the watch window (bottom right of screen), click under "name" and enter ERR,hr

- The reason WHY GetProcAddress failed will be listed next to the name you entered. (That ERR,hr is just a debugger thing which calls GetLastError() for you and converts the error code to text. The docs for GetProcAddress mention that if it fails, the _reason_ can be found with GetLastError()).


If the reason is something like "invalid handle", then the LoadLibrary probably failed. If the reason is something like "not found" or "file not found", then the version of the DLL which the debugger is loading doesn''t have the function you''re trying to get the address of (e.g. an older version of the DLL from before you put any exports in)

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Thanks for all your help. It was something very simple but hard to find due to microsoft. There is a dll with the same name in the windows/system32 dir "console.dll" this one does of course not implement my functions. And win xp perfers to load dlls from it''s system32 dir before loading the dlls from the application dir. So i just changed the name of the dll and voila, all works.

----------------------------
By CommanderXXL
Commander@bredlmuc.de
----------------------------

Share this post


Link to post
Share on other sites