Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1129
  • Last Modified:

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..
0
ewong_111
Asked:
ewong_111
  • 2
1 Solution
 
jkrCommented:
>>extern "C" BOOL __declspec(dllexport) __stdcall InitHook()

You need to leave out the '__stdcall', since that will cause a different name decoration. It should just be

extern "C" BOOL __declspec(dllexport) InitHook()
0
 
jkrCommented:
>>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
0
 
ewong_111Author Commented:
jkr.. u are really the genius here.. :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now