混合 c# 和 vc++ [英] Mixing c# and vc++

查看:32
本文介绍了混合 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#:

这篇关于混合 c# 和 vc++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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