c++dllexport

Exporting a C++ Function from a dll without extern "C"


Objective: Application should be able to load a dll dynamically using LoadLibrary and call its exported function using GetProcAddress.

My dll class has a function returning a unique_ptr of the class type.

I want to export this function such that the application can call this function using getProcAddress after dll is loaded successfully.

Using extern "C" will not allow to use a C++ class(unique_ptr class template, in this case) in the function signature.

I know, If do not use extern "C", it will export the function ( via __declspec(dllexport) ) with a mangled name.

The client will not know the mangled name during the call to getProcAddress, so how will a client call this function?

Is there a way to export such a function?


Solution

  • Yes, the old-fashioned way. Looking up functions by name is the "modern" way (although it predates Windows 95). The old way is to look them up by ordinal.

    You'll need to provide a module definition file with EXPORTS to number your functions.