Solved

Problems with GetProcAddress and LoadLibrary

Posted on 2004-10-04
3
1,039 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

773 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