Hi All,
I have a question that I cannot figure out.
I have DLL that will export class and some C functions.
Should I enclose both definition (.cpp) and Implementation(.h) with extern C? something like below?

class TestClass{
//some stuffs here
extern "C" {
void myFunc(int x, int y);
void myFunc2(int a, int b);



//class implementation here 

extern "C" {
void myFunc(int x, int y){
//some stuff
void myFunc2(int a, int b){
 //more stuffs



Only if the DLL will be used by to C and C++ programs.

I use C functions to export C++ Classes to avoid name mangling

So, am I right?

Edited 6 Years Ago by Stefano Mtangoo: n/a

functions in *.c files can't use c++ classes. And functions in *.cpp file are mangled unless extern "C" is used.

Edited 6 Years Ago by Ancient Dragon: n/a

anthother question though little unrelated to this thread, I have code below of function pointer that throws error. Could you help me spot where I mix void and void*?

error message
error: invalid conversion from 'void*' to 'void (*)(wxString)'

typedef void (*helloSteve)(wxString);//takes string and Shows it!
helloSteve myFunc = myDLL->GetSymbol(wxT("helloSteve"));
This question has already been answered. Start a new discussion instead.