Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,
I have to write code in my C++ DLL to implement events used by external code.
I implemented a function to pass event handler pointer to the DLL in the main library .cpp file:
C++
extern "C" void WINAPI SetEventHandlers(void (*CashierDisplayEvent)(char Text[256]))
{
	CSharedData::CashierDisplayEventRef = CashierDisplayEvent;
}

I declared the function pointer in another class named "CSharedData" as following:
C++
static void (*CashierDisplayEventRef)(char Text[256]);

When I try to compile this, I get the following error:
error LNK2001: symbole externe non résolu "public: static void (__stdcall* CSharedData::CashierDisplayEventRef)(char * const)" (?CashierDisplayEventRef@CSharedData@@2P6GXQAD@ZA)	ccvJIL.obj	ccvJIL

fatal error LNK1120: 1 externes non résolus	c:\Projects\Visual Studio Projects\JILtreibauf\Release\ccvJIL.dll	1	ccvJIL

I suspect a problem with mangling of C++ function naming but my knowledge is limited in this subject.
Your help is welcome.
Regards.
Posted
Comments
Sergey Alexandrovich Kryukov 26-Mar-13 10:09am    
You show this definition:

CashierDisplayEventRef

But do you have CSharedData::CashierDisplayEventRef? This is not the same.
Where is your class/struct CSharedData?

By the way, why do you 'unmangle' SetEventHandlers at all? You could use the name as is in the application using this DLL. All import systems usually allow the definition of the import names.
—SA
dev_at_ccv 26-Mar-13 10:13am    
I 'unmangle' because the DLL has to be used by a pure C code.
Sergey Alexandrovich Kryukov 26-Mar-13 10:36am    
Even pure C can use them mangled name. But this is not the point.
—SA
dev_at_ccv 26-Mar-13 10:42am    
OK... I didn't know. Thank you for your help.
Sergey Alexandrovich Kryukov 26-Mar-13 11:06am    
Sure. You got some correct answers, but I told you in the very beginning that your function is really not defined.
Good luck,
—SA

You have probably forgotten to define the static pointer in your cpp file of class CSharedData. There should be a definition:
C++
void (*CSharedData::CashierDisplayEventRef)(char Text[256]) = 0;

That's where the unresolved external originates from.
 
Share this answer
 
You've declared a static member CashierDisplayEventRef but have you actaully created such a member?
Static members need to be defined and initialised outside the class declaration. Do you have a line in a .cpp file somewhere like:-
void (*CSharedData::CashierDisplayEventRef)( char[256] ) = 0;


Don't take my syntax too literally, I can never remember the correct way of refering to a function pointer member which is why I usually use a typedef for the function pointer type in the header file.
//in the .h before the CSharedData declaration

typedef void (*CashierEventCallback)( char[256] );

//inside the class declaration

static CashierEventCallback m_spEventCallbackFunc;

//in the .cpp

CashierEventCallback CSharedData::m_spEventCallbackFunc = 0;
 
Share this answer
 

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