0

I'm trying to export method from DLL which returns STL object. I'm using MFC.

For example in my dll I have:

std::map<CString, CString> __declspec(dllexport) __stdcall MyMethod(CString str1, CString str2, bool boolValue)
{
    //here create map
    std::map<CString, CString> map;
    map.insert(std::make_pair("key1", "value1"));
    return map;
}

And I'm trying to load dll file in my exe app:

//Here I'm sure dll is loaded in proper way
HINSTANCE dllHandle = dllHandle = LoadLibrary("mydll.dll");

//Then I'm getting pointer to exported method:
typedef std::map<CString, CString>(__stdcall *DllMyMethod)(CString str1, CString str2, bool boolValue);

//This is my class member:
DllMyMethod callMyMethod;

//And getting this function pointer
callMyMethod = (DllMyMethod)GetProcAddress(dllHandle, "MyMethod");

And unfortunately, callMyMethod pointer is empty. Exe app and dll app is created with Visual Studio 2013 with this same settings.

How can I export this method in proper way?

drewpol
  • 665
  • 1
  • 6
  • 26
  • 1
    The best way to export from a dll is to avoid any types which may deallocate the memory your dll has allocated. stl is to be avoided, since you have no guarantees the dll and its caller are abi compatible. – Michaël Roy Nov 07 '17 at 22:22
  • Yes, I figured out another way for passing parameters. I used base types for passing data. That solved my problem and I was able to use C style decoration. – drewpol Nov 07 '17 at 22:55

0 Answers0