在c++和c#代码之间进行调用
Make calls between C++ and C# code
我打算将游戏移植到Windows Phone 8。cocos2d-x创建的Visual Studio项目有一个名为MyGameComponent的c++项目,它是一个名为MyGame的c#项目的依赖项。在MyGame中,cocos2d-x提供了一个LocalizedStrings.cs
文件。我希望能够调用那个文件,这样我就可以使用本地本地化系统。我该怎么做呢?
我还想在其他功能中使用它,所以请不要建议其他方法来进行本地化。
我使用cocos2d-x v2.2.5.
你可以将委托从c#传递给c++组件。
在你的c++组件中,你将定义一个委托和一个方法调用来设置该委托,像这样:
public delegate Platform::String^ GetTranslatedStringDelegate();
public ref class Component sealed
{
public:
void SetDelegate(GetTranslatedStringDelegate^);
private:
Platform::Agile<GetTranslatedStringDelegate> m_delegate;
}
然后在你的c#中,你可以创建一个与委托签名匹配的函数,并将其传递给你的组件:
public string GetTranslatedString()
{
return "translated string";
}
// elsewhere in your C# code
component.SetDelegate(GetTranslatedString);
然后在你的c++中,只要你需要得到一个翻译过的字符串,你就可以调用委托方法。
编辑:我写了一篇关于这个话题的博文- http://robwirving.com/2014/07/21/calling-c-methods-c-winrt-components/
如果你正在使用Managed c++,那么你只需要在你的c++项目中添加c# dll作为参考。然后像往常一样调用你的c# Dll。
ManagedCSharp::ManagedClass::ShowValue();
其中ManagedCSharp是命名空间,ManagedClass是类,ShowValue是方法
相关文章:
- 如何防止clang格式在流运算符调用之间添加换行符<<
- DirectX 9 在重置调用之间保留状态
- Vulkan是否需要在多个具有透明度的平局调用之间进行同步
- 静态模板类成员函数的这两个调用之间有什么区别?
- 在cython调用之间保持数据帧的状态
- C++:cout 和函数调用之间的计算顺序
- unix中选择和轮询系统调用之间的功能差异
- 如何在函数调用之间存储 deque 值
- 如何在c/c++中使函数调用之间的变量值持久化
- 连接线程(阻塞调用线程直到线程终止)和普通函数调用之间的区别是什么
- GDI - 是否可以在WM_PAINT调用之间将位图保存在内存中
- C++ 数字库:std::uniform_int_distribution<>,更改调用之间的分布边界
- 来自托管库的调用之间本机库中静态变量的值
- 按引用调用和按指针调用之间的差异
- 链式静态函数调用之间的参数求值顺序
- 对伪随机数生成器的相同调用之间的不同行为
- 在来自C++应用程序的成功调用之间保留dll中的状态
- 如何在c++ dll中实例化一个类,使它在函数调用之间保持内存
- 我可以在函数调用之间在c++ DLL中维护内存吗?
- 带和不带()的构造函数调用之间的区别