Solved

Problems with GetProcAddress and LoadLibrary

Posted on 2004-10-04
3
1,014 Views
Last Modified: 2012-06-22
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
Comment
Question by:ewong_111
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 12221531
>>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
 
LVL 86

Expert Comment

by:jkr
ID: 12221551
>>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
 
LVL 2

Author Comment

by:ewong_111
ID: 12221793
jkr.. u are really the genius here.. :)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now