Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ DLL Events
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:
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.
Regards.
Posted 26-Mar-13 5:04am
Comments
Sergey Alexandrovich Kryukov at 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 at 26-Mar-13 10:13am
   
I 'unmangle' because the DLL has to be used by a pure C code.
Sergey Alexandrovich Kryukov at 26-Mar-13 10:36am
   
Even pure C can use them mangled name. But this is not the point.
—SA
dev_at_ccv at 26-Mar-13 10:42am
   
OK... I didn't know. Thank you for your help.
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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;
 
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 299
2 BillWoodruff 174
3 /\jmot 170
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2014
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