从调用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...

我写在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

阅读全文

相关推荐

最新文章