Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting C++ Object from DLL [closed]

Tags:

c++

dll

I am creating a wrapper DLL for boost containers (map, vecrtor, set..). In my application, I want to export the C++ object from the DLL to the client. So I am left with two option for exporting:

  1. Export the C++ Class using (_declspec)dllexport and use in client.
  2. Provide a abstract class with only pure virtual functions (like interfaces in COM) and export only a single method from the DLL (for instance CreateMap).

I am using the containers(map, vector..) extensively in the client.

Can any one please help me, which will be the best method for exporting?

like image 211
Ushus Avatar asked Dec 17 '25 17:12

Ushus


1 Answers

Having C++ classes and STL containers at the DLL interface boundaries is very fragile and highly constraining for your clients: in fact, both the DLL and the client EXEs must be built with the same VC++ compiler version, and dynamically link to the same flavor of the CRT.

It's much safer and better practice to build DLLs exporting a pure C interface. Note that you can use C++ inside the DLL boundaries (this is basically what many Win32 C-interface APIs do).

As an alternative you may export pure C++ abstract classes (interfaces) from the DLL, which is basically what COM does.

You may find this CodeProject article interesting.

like image 113
Mr.C64 Avatar answered Dec 19 '25 05:12

Mr.C64



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!