混合 c# 和 vc++
我有一段 c# 代码片段,我一直试图将其翻译成 vc++,但遇到了一些困难.所以,我想知道混合 c# 和 vc++ 是否可能或可取;也就是说,我可以从 vc++ 调用我的 c# 函数,反之亦然.如果是这样,它有什么技巧吗?如果不是,为什么?
I've got a code snippet of c# that I've been trying to translate into vc++, but I'm having some difficulties. So, I'm wondering if it is possible or advisable to mix c# and vc++; that is to say, can I call my c# function from vc++ and vice-versa. If so, are there tricks to it? If, not, why?
从 C# 调用 C++ 代码非常简单,您应该能够找到大量关于 Pinvoke 和其他类型互操作的文章.
Calling C++ code from C# is easy enough and you should be able to find plenty of articles on Pinvoke and other types of interop.
用于从 C++ 调用 C# 代码 - 如果您的 C++ 应用程序是托管的,那么您应该能够直接从您的 C++ 应用程序引用 C# 程序集并照常使用它.
For calling your C# code from C++ - if your C++ app is managed then you should be able to directly reference the C# assembly from your C++ app and use it as normal.
如果 ypu C++ 代码不受管理,那么您将需要使用某种互操作来允许您的 C++ 程序集调用 C# 代码,唯一能想到的方法是 COM.
If ypu C++ code is not managed then you will need to use some sort of interop to allow your C++ assembly to call C# code, the only way of doing this that springs to mind is COM.
尝试其中一些链接以获取有关 COM 与 C# 互操作的更多信息:
Try some of these links for more information on COM interop with C#: