Link to home
Start Free TrialLog in
Avatar of ewong_111
ewong_111

asked on

Problems with GetProcAddress and LoadLibrary

Hi,

I have been bothered by this bug for a few days and I wish if anyone could give me a little hints or help, I will be very appreciating..

I have been trying to build a DLL for a hook.. so I started by building a regular DLL and I ran into troubles of not having the dllMain() which created problems..
So I start over again and built a similar DLL using the extension DLL.

I built the export function as the following:

extern "C" BOOL __declspec(dllexport) __stdcall InitHook(){
  ......
  ......
}

I don't see a header file for the extension DLL so I did not declare it in any header file.. is that valid?

Then I built a dialog box based application and try to call the DLL function.. I tried both implicit and explicit..

declare the BOOL __declspec(dllimport) __stdcall InitHook(); in the header file of the dialog box based application, added the .lib file to the resource, and put the .dll in the %SystemRoot%\system32 folder..

but it didn't work by having error LNK2019: unresolved external symbol..

so I turned to another explicit:

typedef BOOL (WINAPI* LPHOOK)();

hDLL = LoadLibrary("MyHook.dll");
HINSTANCE hDLL;
LPHOOK lp_InitHook;
if (hDLL){
  lp_InitHook = (LPHOOK)GetProcAddress(hDLL,"InitHook");
}

something like that..
but, although it complies okay.. it only returned a valid hDLL but with a NULL lp_InitHook..

I have been trying a lot of different methods but I am not sure what is still missing..
Any help or suggestion is welcome.. please help..
Thanks a million..
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>a different name decoration

Just to clarify - the '__stdcall' attibute will export the function like

_InitHook@<some_ordinal>

You can verify that using

dumpbin.exe /exports MyHook.dll

or using the dependency walker from www.dependencywalker.com
Avatar of ewong_111
ewong_111

ASKER

jkr.. u are really the genius here.. :)