调用从非托管code管理code [英] calling managed code from unmanaged code

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

问题描述

我想从非托管的C打电话给我的。NET code ++。我的过程入口点是基于.NET的,所以我不担心宿主CLR。我知道它可以使用COM包装为.NET对象来完成,但我想访问托管类的单个静态方法,所以COM是不是我的最短/最快的途径。

I want to call my .NET code from unmanaged C++. My process entrypoint is .NET based, so I don't have to worry about hosting the CLR. I know it can be done using COM wrappers for .NET objects, but I would like to access individual static methods of managed classes, so COM isn't my shortest/easiest route.

谢谢!

推荐答案

假设你正在谈论真正的非托管code - 不只是本地C ++中使用/ clr编译混合模式组件运行 - 最简单的方法是创建一个包装到你的.NET code在C ++ / CLI。然后,您可以通过只将它们标记与__declspec(dllexport)的出口C ++ / CLI的方法。

Assuming you are talking about real unmanaged code - not just native C++ running in a mixed-mode assembly compiled with /clr - the easiest way is to create a wrapper to your .NET code in C++/CLI. You can then export the C++/CLI methods by just marking them with __declspec(dllexport).

另外,如果你有过的非托管code调用控件,可以封的函数指针到.NET方法,并将其传递给非托管code。

Alternatively, if you have control over the invocation of the unmanaged code, you can marshal function-pointers to your .NET methods and pass them to the unmanaged code.

这篇关于调用从非托管code管理code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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