Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unresolved Externals when using dll's 1

Status
Not open for further replies.

AndyHollywood

Programmer
Oct 7, 2001
30
GB
Hello, I wonder if anybody can help me to get rid of the unresolved external linking errors that i get in my code?!

I have written a program that requires the use of a dll to deploy system wide hooks to monitir the users interactions, it was originally an example from msdn and i had planned to modify it to collect user information, but i can't get it to compile!

A link to my code:
It gives me erros along the lines of:
Code:
key32.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall InitHooksDll(struct HWND__ *,int)" (__imp_?InitHooksDll@@YGHPAUHWND__@@H@Z) 
key32.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall PaintHooksDll(struct HDC__ *)" (__imp_?PaintHooksDll@@YGHPAUHDC__@@@Z) 
key32.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int __stdcall InstallFilter(int,int)" (__imp_?InstallFilter@@YGHHH@Z)

I I have no idea what they mean or how to solve them! If somebody could explain what they mean i would be grateful, or if somebody could tell me how to solve them i would be exstatic!!

Cheers in advance

Andy
 
Hi Andy,

Well, these messages mean that the key32.cpp code has defined some functions to be imported from a DLL. The linker can't resolve these references because it does not have the .lib File for the DLL. You need to enter this in the project/settings/Link Object/library modules list.




:) I just can't help it, I like MS...:)
 
I have already done that I think, I also tried copying the lib into the directory to make things easier but it didn't work?!

Is this the only reason why i would get these errors?
 
Ok, the problem is that your dll is a C program, but key32 is C++. The C++ compiler creates "mangled" names for functions. You have to tell it that the keydll functions are C code. Simples way is to put the following in keydll.h

#if defined(__cplusplus)
extern "C" {
#endif
int DLLEXPORT WINAPI InitHooksDll(HWND hwndMainWindow, int nWinLineHeight);
int DLLEXPORT WINAPI PaintHooksDll(HDC hDC );
int DLLEXPORT WINAPI InstallFilter (int nHookIndex, int nCode );
char DLLEXPORT *szMessageString(int ID);
#if defined(__cplusplus)
}
#endif

extern "C" tells the C++ compiler that the folowing code should have C linkage. The __cplusplus sysmbol is defined only by the C++ compiler.
:) I just can't help it, I like MS...:)
 
I have pasted that code into the header file, but it still return the four unresolved externals!

Do i have to change the actual function? in the .c file?

or is there another problem?
 
I successfuly compiled and linked the code last night, after I'd made a few slight changes to the DLLEXPORT symbols. The value under projekt/settings doesn't match the value in the header and some of the functions don't have the symbol which gave a few warnings. But I don't have the code here.

Basically there's nothing much wrong. You need the code just in the one header. In C it will have no effect, and in the C++ code it will ensure that C linkage is used. You need to check that the symbols are being exported (look in the .lib file with Notepad, for example). If the __cplusplus stuff is right, you should see different names for the symbols which are missing, if they are still full of ?@@@ stuff you haven't got it quite right.

If you leave your email address I could send my changed code back to you tonight.
:) I just can't help it, I like MS...:)
 
I'll have aplay later on when iget back from lectures!

If you don't mind try sending it to A.Dunn@Orange.net

Thanks very much for your help!

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top