Search code examples
c++dllvisual-studio-2005clrmixed-mode

Using mixed DLLs from /clr:pure projects


I'm building a project along with a Dll.

The Dll must support native code so I declared it as a /clr. My project was initialy also a /clr project and everything was fine. However I'd like to include some NUnit testing so I had to switch my main project from /clr to /clr:pure.

Everything still compiles but any Dll call generates a runtime error. When I revert back to /clr everything is ok

In my Dll, exported functions are declared as follow :

#define DllExport   __declspec( dllexport )
DllExport bool DisplayScan(bool bShow, bool bAllPasses) { }

I also made a .def file containing the real names of all the exported functions

LIBRARY "Controller"
EXPORTS
DisplayScan

From my main project my imports are declared as follow :

#define _DllImport [DllImport("Controller.dll", CallingConvention = CallingConvention::Cdecl)] static
_DllImport bool DisplayScan(bool bShow, bool bAllPasses)

Anyone ever encountered such a problem?


Solution

  • Ok everything is working now

    In fact, it has been working from the beginning.

    Moral : don't try to cast a char* into a std::string

    Weird thing : its ok in /clr until you return from the function. It crashes right away in /clr:pure