Skip to main content
GameDev.net gamedev.net
🔒 Locked

DLL loading problems.. GetProcAddress

Started by AndersO Feb 12, 2004 at 4:13 AM 6 replies 3.1k views
Original Post
AndersO
AndersO
I''m doing a dll on my pocketpc and it fails when I try to get a function pointer from it. I have this in the dll code: __declspec (dllexport) void InitFunc (void); void InitFunc (void) { ... } And this is how I load the dll in the main program: HINSTANCE hDll; FARPROC dllInitFunc; void LoadLib (void) { DWORD err; hDll=LoadLibrary(L"mylib.dll"); if (hDll==NULL){ MessageBox(hWnd,L"Failed to load dll",L"Error",MB_OK); return; } dllInitFunc=GetProcAddress(hVibradll,L"InitFunc"); if (dllInitFunc==NULL){ err=GetLastError(); MessageBox(hWnd,L"Failed to get proc address",L"Error",MB_OK); } } dllInitFunc becomes NULL and err is 87, ERROR_INVALID_PARAMETER. What am I doing wrong?
Sneftel
Sneftel
quote:

hDll=LoadLibrary(L"mylib.dll");
dllInitFunc=GetProcAddress(hVibradll,L"InitFunc");


Perhaps the fact that you''re not passing in the correct DLL handle?



"Sneftel is correct, if rather vulgar." --Flarelocke
SiCrane
SiCrane
Also, with name mangling, the name of the function stored in the export table of the DLL may not be "InitFunc". You should check a export dump of the DLL to make sure you''re using the right name.
AndersO
AndersO
Oh, thats a typo.. I have the right handle...

Hmm, I''ll check the function name but I think its correct.
Stonicus
Stonicus
FARPROC is a typedef to a function pointer that returns an int. Your function in your DLL is void.

typedef void (*MY_PFN)(void);
MY_PFN dllInitFunc;

that should work...

also, just for some cover yer a$$, not a bad idea to cast the GetProcAddress...

dllInitFunc = (MY_PFN)GetProcAddress(hDll, "InitFunc");



[edited by - stonicus on February 12, 2004 3:48:31 PM]
MaulingMonkey
MaulingMonkey
quote:
Original post by AndersO
dllInitFunc=GetProcAddress(hVibradll,L"InitFunc");
What am I doing wrong?


try replacing that line with:

dllInitFunc=GetProcAddressA(hDll,"InitFunc");

I''m guessing that the unicode vs ascii stuff is the problem.
AndersO
AndersO
Ah yea!.. That was it, extern "C". Thanks! Guess it was name mangling after all.

And thanks all for your suggestions!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.