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?
myfunc.h

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

}

myfunc.cpp

//class implementation here 

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

}

Thanks!

Recommended Answers

All 4 Replies

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

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?

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

Thanks,
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"));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.