从调用C ++ C#功能? [英] Calling C# function from C++?

查看:210
本文介绍了从调用C ++ C#功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在MonoTouch的一个应用程序,这也使得使用了C ++库,所以我一直在使用P / inoke调用C ++函数从C#做各种各样的事情。然而,有新兴的一些场景,我想C ++ code调用C#函数。

I'm writing an app in monotouch which also makes use of a C++ library, so I've been using p/inoke to call C++ functions from C# to do a variety of things. However there is emerging a few scenarios where I would like the C++ code to call C# functions instead.

所以是这样的:

void CPlusPlusFunction(Pointer* stuff)
{
    //do stuff

    CSharpFunction(*stuff);
}

这是可能的,如果是这样我怎么能走呢?而不是调用一个函数或许才有可能传递一个委托到C ++调用,如果是如何将这项工作?我真正想要做的是立即在一个功能点传递一些信息到C#。

Is this possible and if so how can I go about it? Perhaps instead of calling a function would it be possible to pass in a delegate to C++ to invoke and if so how would that work? All I really want to do is pass some information to C# immediately at that point in a function.

感谢您的帮助!

推荐答案

当然可以。然而,AOT编译器,用于编译设备MonoTouch的code,必须意识到这样的回调,因此它可以生成相应的code。因此你的回调必须与装饰在 [MonoPInvokeCallback] 属性。

Yes you can. However the AOT compiler, used for MonoTouch code compiled for devices, must be aware of such callback so it can generate the appropriate code. As such your callbacks must be decorated with the [MonoPInvokeCallback] attribute.

http://developer.xamarin.com/guides/ios/advanced_topics/limitations/#Reverse_Callbacks

这篇关于从调用C ++ C#功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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