Solved

Problems with GetProcAddress and LoadLibrary

Posted on 2004-10-04
3
1,067 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

738 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