需要一个好的示例代码,我可以将c#dll中的回调函数调用为c ++代码。 [英] Need a good sample code where I can call a callback function from c# dll into a c++ code.

查看:219
本文介绍了需要一个好的示例代码,我可以将c#dll中的回调函数调用为c ++代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c#dll女巫收到make计算并生成结果,完成后,我想调用一个回调函数到c ++  exe。谢谢

I have a c# dll witch receives makes calculation and generates results, when this is done, I like to invoke a callback function into c++ exe. Thanks

推荐答案

通常你从函数指针创建一个委托并调用它。如何获得委托取决于您获取函数指针的位置/方式。如果你在pinvoke或com方法签名中使用委托类型,那么封送程序将为你创建函数指针的委托
,否则你可能需要使用
Marshal.GetDelegateFromFunctionPointer()
。在任何一种情况下,您几乎肯定无法使用Action<>或者Func<>因为委托类型需要以与pinvoke方法大致相同的方式进行修饰。
Normally you create a delegate from the function pointer and call that. How you get the delegate depends on where/how you get the function pointer. If you use a delegate type in the pinvoke or com method signature, then the marshaler will create the delegate from the function pointer for you, otherwise you will probably need to use Marshal.GetDelegateFromFunctionPointer(). In either case, you almost certainly won't be able to use Action<> or Func<> as the delegate type will need to be decorated in much the same way as a pinvoke method.


这篇关于需要一个好的示例代码,我可以将c#dll中的回调函数调用为c ++代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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