Click here to Skip to main content
12,998,423 members (89,070 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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:
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:
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.
Posted 26-Mar-13 4:04am
Sergey Alexandrovich Kryukov 26-Mar-13 10:09am
You show this definition:


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.
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.
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,
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

That's where the unresolved external originates from.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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;

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100