gpt4 book ai didi

c# - 在 C++ 项目中使用 C# DLL

转载 作者:可可西里 更新时间:2023-11-01 15:47:59 26 4
gpt4 key购买 nike

我想在 c++ 项目(visual studio 2003)中使用用 c#(visual studio 2008)制作的 dll。怎么做 ?请帮忙

最佳答案

不仅仅是 COM 互操作, MSDN FAQ 还列出了鲜为人知的方法:

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

There are basically four methods to call .NET assembly from native VC++ code. Microsoft All-In-One Code Framework has working examples that demonstrate the methods.

  1. Native VC++ module calls CLR Hosting APIs to host CLR, load and call the .NET assembly. (All-In-One Code Framework Sample Code: CppHostCLR)

  2. If the .NET assembly can be exposed as a COM component, native VC++ module can call into the .NET assembly through .NET – COM interop. (All-In-One Code Framework Sample Code: CppCOMClient)

  3. Reverse PInvoke: the managed code call native passing a delegate the native code can call back. (All-In-One Code Framework Sample Code: CSPInvokeDll)

  4. If the module containing native VC++ code is allowed to enable CLR, the native VC++ code can call .NET assembly directly through the “It Just Works”, or “IJW”, mechanism. (All-In-One Code Framework Sample Code: CppCLIWrapLib)

关于c# - 在 C++ 项目中使用 C# DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3799907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com