在MFC DLL导出函数中传.net对象,不可以,有编译错误如下:
error C3395: 'MyClass::Function' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention
解决方法是,为参数包上 gcroot<>.
class AFX_EXT_CLASS MyClass
{
public:
void Function(MyDotNetClass^ obj); //compile error
void Function(gcroot<MyDotNetClass^> obj); // this is correct
}