开发者

C++ COM Interop: Using C# namespace with dot notation in c++

I have a C# namespace defined as A.B.C which I tried using in a C++ header with

using namespace A::B::C;

and I get error C2653: A is not a class or n开发者_Go百科amespace.

The unmanaged project is referencing the managed project with this namespace. How do I get around this? TIA.


COM Interop doesn't let you do that. COM interop lets you retrieve a C++ COM interface pointer to a .NET object, using e.g. CoCreateInstance.

If you want to refer to the C# namespaces and types directly (not through a COM interface pointer), you want C++/CLI (the /clr option for Visual C++).


Calling managed code from unmanaged code is kinda nasty. You have to do tricky stuff to get a function pointer to the managed function. See this example for how to do it:

http://www.codeproject.com/KB/mcpp/unmanaged_to_managed.aspx


COM does not have support for C# namespaces, so there's no way of doing what you want. Sorry :(.

As Ben Voight mentioned, you can use C++/CLI if you want to preserve the C# namespaces.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜