跨 C/C++(非托管)和托管 C# 代码共享通用定义 [英] Shared common definitions across C/C++ (unmanaged) and managed C# code

查看:35
本文介绍了跨 C/C++(非托管)和托管 C# 代码共享通用定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组由 C# 托管组件和非托管 C/C++ 组件使用的结构定义.现在,相同的结构体定义分别存在于 C/C++ 和 C# 代码中——导致重复和相关的混乱.维护可从 C# 和 C/C++ 使用的单个定义的最佳方法是什么?谢谢!阿米特

I have a set of struct definitions that are used by both C# managed components and unmanaged C/C++ components. Right now, the identical struct definitions exist separately in C/C++ and C# code - causing duplication and related chaos. What's the best way to maintain single definitions that can be used from both C# and C/C++? Thanks! Amit

P.S.:我是一个 C/C++ 人,所以如果有明显的方法可以做到这一点,我可能会完全错过它!

P.S.: I'm a C/C++ guy so if there's an obvious way to do this, I might be missing it completely!

推荐答案

很明显,我不熟悉您的项目,但您是否考虑过在 C++/CLI?借助 C++/CLI 编译器为您执行的It Just Works"黑客攻击,您可以多次使用本机代码来回编组和共享托管类型.

I'm not familiar with your project(s), obviously, but have you considered building a managed bridge for your library in C++/CLI? With the "It Just Works" hackering the C++/CLI compiler does for you, many times you'll be able to marshal and share managed types with native code and back and forth.

同样,如果没有更多细节,我不知道它是否适合您,但它可能值得研究.

Again, I don't know if it's right for you without more specifics, but it might be worth looking into.

这篇关于跨 C/C++(非托管)和托管 C# 代码共享通用定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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