Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
Hi,
I have a FuncA() inside the EXE. FuncA() is called from inside the EXE and from inside a DLL. Therefore, I wrote a callback function for FuncA() so that the DLL can call to it. Hence, I need to export FuncA() so that I can get the function address from inside the DLL.
declspec(dllexport) void FuncA(){ return; }//declspec(dllexport) is to be able to get the function address.

However,
Because FuncA() is called from DLL AND from inside the EXE as well,
my problem is the declaration of funcA() inside the EXE. That declaration will be used by the functions inside the EXE.
void FuncA();//If I write it this way I get the following error:
error C2375: 'FuncA' : redefinition; different linkage

And,
declspec(dllimport) void FuncA();//If I write it this way, I get the following warning and the program hangs.
warning LNK4049: locally defined symbol _FuncA imported

How do I write the proper declaration?
Note: Windows, Visual Studio 2008, Standard-C
Posted
Updated 7-Mar-11 21:13pm
v4

As far as I understand your comments, you need to use pre-processor directives in any hader file using to declare your function.

// in AnyHaderFile.h for FuncA() declaration
#ifdef _WITHINDLL_
declspec(dllimport) void FuncA();
#else
declspec(dllexport) void FuncA();
#endif

// in your DLL file, include it with after definition of _WITHINDLL_
#define _WITHINDLL_
#include "AnyHaderFile.h"

// in your EXE file, you just need to include without _WITHINDLL_

#include "AnyHaderFile.h"


In this particual case, the function is implemented in EXE (not in DLL unlike as usual).

I hope, I understand right.
 
Share this answer
 
Comments
kenny00100 9-Mar-11 3:09am    
Thank you for your answer! I was looking for the declaration in the EXE as you wrote above. But, you gave a more fulfilling answer anyway : )
Thank you.
I'm not sure I understand your problem correctly, but I think you have FuncA declared inside your exe file and in your dll? And in your exe you want to be able to call both the FuncA from the exe itself and the dll?
The easiest solution seems to be to just rename one of them so they no longer conflict.
 
Share this answer
 
Comments
kenny00100 8-Mar-11 3:11am    
Thank you for replying,
Actually, my situation is that FuncA() is defined inside EXE. And, it is also called from functions that exist inside the EXE. Furthermore, it is called by functions outside the EXE (inside the DLL).
The above is (are) the declaration of FuncA() inside the EXE that the other functions(EXE functions) use. I cannot seem to find the write format.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900