开发者

Calling C# function from 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.

So something like:

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

    CSharpFunction(*stuff);
}

Is this possible and i开发者_如何学Cf 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.

Thanks for any help!


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


You can ask C# to export functions from a shared library, just as native libraries can do. In addition, C# can convert delegates to function pointers of the same signature, which you can pass into C++.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜