Linking functions problems in dll 
Author Message
 Linking functions problems in dll

I've a problem importing same functions from a dll:

I've declared them in a header file (hookDLL.h)  in this way:

#ifndef HOOKDLL_H
#define HOOKDLL_H

#ifndef HOOKLIBAPI
#define HOOKLIBAPI  __declspec(dllimport)
#endif

HOOKLIBAPI BOOL WINAPI Hook_Start (HWND hWnd);
HOOKLIBAPI BOOL WINAPI Hook_Init (HWND hWnd);
HOOKLIBAPI BOOL WINAPI Hook_Stop ();
HOOKLIBAPI BOOL WINAPI Hook_Installed ();

#endif // HOOKDLL_H

I've implemented them into the implementation file (hookDLL.c):

#define HOOKLIBAPI   __declspec(dllexport)
#include "hookDLL.h"

BOOL WINAPI Hook_Init (HWND hWnd)
{
 m_hwndOut=hWnd;
 return (m_hwndOut!=NULL);

Quote:
}

...

At this point the compiler build the dll and the .lib and .exp files
correctly.

Then I try to use them into the exe in this way:

#include "stdafx.h"
#include "Spyer.h"

#include "MainFrm.h"
#include "SpyerDoc.h"
#include "SpyerView.h"
#include ".\hookDLL\hookDLL.h"

...
void CSpyerView::OnHook()
{
 if (Hook_Installed ()) {
  AfxMessageBox("Terminare l'hook corrente prima di effettuare una nuova
cattura!",MB_ICONEXCLAMATION);
  return;
 }

Quote:
}

...

And now the linker says me:

Compiling...
StdAfx.cpp
Compiling...
MainFrm.cpp
Spyer.cpp
SpyerDoc.cpp
SpyerView.cpp
Generating Code...
Linking...
SpyerView.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) int __stdcall Hook_Init(struct HWND__ *)"

SpyerView.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) int __stdcall Hook_Start(struct HWND__ *)"

SpyerView.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) int __stdcall Hook_Installed(void)"

SpyerView.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) int __stdcall Hook_Stop(void)"

C:\WINDOWS\Desktop\Projects\Spyer\Debug\Spyer.exe : fatal error LNK1120: 4
unresolved externals
Error executing link.exe.

Spyer.exe - 5 error(s), 0 warning(s)

I link the project with the HookDLL.lib (obvious).
Can you tell me way?  (if you want the complete code its size is 75 kb).

Perhaps the reason is I try to use function from a file wri{*filter*} in C in
another written in C++ ? (I've tried unsuccessfully to use extern "c", but I
wrong something).

Please Help!



Wed, 05 Dec 2001 03:00:00 GMT  
 Linking functions problems in dll
Hi,

It looks as a name mangling problem to me.
C++ uses name mangling and C not, since your mixing
cpp and c files this gives you a headache and the linker to

There are several options:
assuming your compiler is VC++

1 rename the c file into cpp and add it to your project
again.
2 use a compiler switch for the c file so the file will be
compiled as a c++ file
3 make sure that a c++ file sees the declaration of the
function as extern "C"
example:
extern "C" {
void cfun1( void );
void cfun2( void );

Quote:
}

Good luck,
Wibo.

**** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ****



Sat, 08 Dec 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem while linking a DLL function

2. Template Implementaion in a DLL problem linking problem...

3. DLL function calling problems (explicit - only knowing function name at runtime)

4. Linking against exported functions in a DLL

5. Linking error in calling a function exporting from a DLL

6. About explicit linking to DLL functions:

7. DLL doesn't link runtime functions

8. dynamically link to the function in a DLL

9. Calling RAS API functions without linking to DLL

10. Dynamic Linking DLL problem

11. Linking problem on a migrated VC6 Win32 DLL project

12. problem linking to outside dll (oracle client)

 

 
Powered by phpBB® Forum Software