从C调用C# [英] Calling C# from C

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

问题描述

有没有人在C中调用模块的C#模块的工作。我试图寻找互联网上,但没有找到很好的例子。虽然很多网站说,像使用COM互操作,但无法找到一个合适的例子或文章虽然解释它。

如果有人能帮助我在此,这将是巨大的。

谢谢,
Sveerap


解决方案

有不仅仅是COM互操作多,如果你想调入从C或C ++托管code。的还有以下鲜为人知的方法(从 <一所href=\"http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/adce905c-2bd3-4276-be53-c644dd928dfa\"相对=nofollow> MSDN FAQ


  

如何调用从本地的Visual C .NET程序集++?


  
  

有四种基本方法
  从本地VC ++ code调用.NET程序集:


  
  

      
  1. CLR托管API :本土VC ++模块调用的 CLR托管的API 的托管CLR,加载并调用.NET程序集(样本code:的 CppHostCLR )。


  2.   
  3. COM互操作:如果.NET组件可以公开为COM组件,本土VC ++模块可以通过.NET调用到.NET程序集 - COM互操作(样本code: CppCOMClient


  4.   
  5. 反向PInvoke的:托管code调用本地code传递的委托,本土code可以回调(样本code:<一HREF =HTTPS://$c$c.msdn.microsoft.com/windowsdesktop/CSPInvokeDll-b05779d0相对=nofollow> CSPInvokeDll )


  6.   
  7. C ++ / CLI :如果包含本土VC ++ code模块允许的启用CLR ,本土VC ++ code可拨打
      .NET程序集直接(样本code:消费C#库中的原生C或C ++使用C ++ / CLI


  8.   

Has anyone worked on calling a C# module from C module. I tried searching on internet but didn't find good examples. Though lot of sites say something like using COM interop but couldn't find a proper example or article explaining it though.

If someone can help me on this, it would be great

Thanks, Sveerap

解决方案

There is more than just COM interop if you want to call into managed code from C or C++. The are also the following lesser known methods (taken from MSDN FAQ):

How do I call a .NET assembly from native Visual C++?

There are basically four methods to call .NET assembly from native VC++ code:

  1. CLR Hosting API: Native VC++ module calls CLR Hosting APIs to host CLR, load and call the .NET assembly (sample code: CppHostCLR).

  2. COM Interop: If the .NET assembly can be exposed as a COM component, native VC++ module can call into the .NET assembly through .NET – COM interop (sample code: CppCOMClient).

  3. Reverse PInvoke: The managed code calls native code passing a delegate that the native code can call back (sample code: CSPInvokeDll).

  4. C++/CLI: If the module containing native VC++ code is allowed to enable CLR, the native VC++ code can call .NET assembly directly (sample code: Consuming C# Library in native C or C++ using C++/CLI)

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

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