Export class to dll without function

I would like to know how to get rid of the scenery around the function of the class that I need to export to dll. For example, when you have something like this:

extern "C" { __declspec(dllexport) int __cdecl getWhatever(); } 

And you confirm with dependencyWalker that the name of the function that is being exported, you will have exactly the same function name.

But if you do something similar with the class, there will be a bunch of character decorating this function as follows:

 extern "C" { class __declspec(dllexport) Toto { __cdecl Toto(){} __cdecl ~Toto(){} int __cdecl getBlob(float y){return (int)y;} }; } 

In dependencyWalker, you will see the following:

?? 0Toto @@ AAE @XZ

?? 1Toto @@ AAE @XZ

?? 4Toto @@ QAEAAV0 @ ABV0 @@ Z

? @GetBlob Toto @@ AAAHM @Z

So, how to make it clean, as with a procedural function?

Thanks,

+4
source share
2 answers

You cannot disable name management for C ++ classes, and you cannot export them without distortion. C ++ classes support functions that require mangling. For example, overloading functions.

It is also worth noting that mangling is compiler specific. Therefore, if you want your class to be accessible to people using different compilers or even different languages, then exporting C ++ classes from DLLs is a poor design choice.

+5
source

Do not export the class directly, use an abstract interface, as COM does.

Here are some good articles:

Export C ++ classes from DLL

Binary Compatible C ++ Interfaces

&

How to export C ++ classes from DLL

0
source

Source: https://habr.com/ru/post/1396503/


All Articles