So in visual studio i have my solution with two projects, first one is managed c++ code and second one is unmanaged c++ library (waffles). I want to use classes from library in my managed code.
If i simply add ‘include “GMacros.h”‘, then i get ‘cannot compile with /clr’ error. Tried to wrap include in #pragma unmanaged/managed, but it doesnt seem to work.
Is there anything i can do without editing external library code or writing any wrappers?
Unmanaged code can’t be called directly in managed .NET. You need to add
__declspec(dllexport)to your functions’ declarations that should be visible outside the unmanaged library:And then in your managed code write a simple wrapper like this:
Now you can call
Wrapper.MyUnmanagedMethodlike any other static method from you managed code.