What is the correct way to import a C++ class from a DLL? We're using Visual C++.
There's the dllexport/exports.def+LoadLibrary+GetProcAddress trifecta, but it doesn't work on C++ classes, only C functions. Is this due to C++ name-mangling? How do I make this work?
You need to add the following:
extern "C"
{
...
}
to avoid function mangling.
you might consider writing two simple C functions:
SomeClass* CreateObjectInstace()
{
return new SomeClass();
}
void ReleaseObject(SomeClass* someClass)
{
delete someClass;
}
By only using those functions you can afterward add/change functionality of your object creation/deletion. This is sometimes called a Factory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With