Functions from DLL not found

Started by
6 comments, last by CommanderXXL 21 years, 8 months ago
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 ----------------------------
---------------------------- By CommanderXXLCommander@bloomm.de----------------------------
Advertisement

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

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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
----------------------------
---------------------------- By CommanderXXLCommander@bloomm.de----------------------------
Mayeb there''s something wrong with the handle from LoadLibrary. Have you verified that?
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"?
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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
----------------------------
---------------------------- By CommanderXXLCommander@bloomm.de----------------------------
Be careful with that

This topic is closed to new replies.

Advertisement