如何互操作,以C ++与命名空间 [英] How to Interop to C++ with Namespace

查看:85
本文介绍了如何互操作,以C ++与命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++函数,我希望暴露给C#食用。美中不足的是的的C ++代码的声明包装在命名空间

I have a C++ function, that I want to expose to C# for consumption. The catch is that the C++ code declaration is wrapped in namespace:

namespace OhYeahNameSpace
{
 extern "C"  __declspec(dllexport) void Dummy();
}



我的问题是,如何定义相应的C#结构?我认为,C#代码必须意识到 OhYeahNameSpace 的存在,我是正确的。

My question is, how to define the corresponding C# structure? I believe that C# code must be made aware of the existence of OhYeahNameSpace, am I right?

编辑:我想很多人误解我的意思(不,谢谢由于我原来的例如一个错字;固定)。我询问如何通过如果有一个命名空间而导出的功能是住在走。答案之一是缺少这一部分,另外一个说,这不能做,让我绕到了,现在另外一个是目前-1票。

I think a lot of people misunderstand my point ( no thanks due to a typo in my original example; fixed). I am asking about how to go by if there is a namespace for which the exported function is dwell on. One answer are missing on this part, another one says this can't be done and ask me to wrap it around, and another one is now currently with -1 vote.

推荐答案

为什么在C ++ / CLI不换?

Why not wrap in C++/CLI?

//ohyeah.h
namespace OhYeahNameSpace
{
  public ref class MyClass
  {
     void Dummy();
  }
}

//ohyeah.cpp
#include "ohyeah.h"
namespace OhYeahNameSpace
{
void MyClass::Dummy()
{
// call the real dummy in the DLL
}

}

这篇关于如何互操作,以C ++与命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆