开发者

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

开发者 https://www.devze.com 2023-03-16 08:26 出处:网络
I have a C# namespace defined as A.B.C which I tried using in a C++ header with using namespace A::B::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

精彩评论

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