开发者

Problem in accessing members of class in C# DLL from C++ project

I have added a C# DLL into a C++ project as mentioned at MS support, however I was not able to access its variables and methods inside the class. It also says that it's a struct and not a class, I don't know if it is important but I thought I should mention it is as well. Whenever I write . or -> or :: after the object, nothing appear. But it appear at the name of the class only al开发者_如何学Pythonthough they are not static.


Starting with Visual Studio 2005, you can use C++/CLI, Microsoft's ECMA-approved C++ dialect that allows using managed and unmanaged code together. In VS2005, there are the "Managed Extensions for C++", with which you can achieve roughly the same, but you have to use horribly-looking syntaxes for writing managed code in C++ (with lots of double underscores).

With C++/CLI, you can mix managed and unmanaged code in your project, and use C# types directly. IMHO, that's a lot easier than using COM.


To increase compatibility I don't export a class from my DLLs (C# or C++). Instead I expose the class's functions, but the first parameter of each function is a pointer to the class itself. Of you could you also need to expose a: void* CreateMyClassInstance(), and a: DestroyMyClassInstance(void* pInstance).


Read the article posted on below link

http://www.codeproject.com/KB/cs/InterOp.aspx

I think it would help you out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜