如何在C#程序中使用C ++文件和类? [英] How do you use C++ files and classes in a C# program?

查看:84
本文介绍了如何在C#程序中使用C ++文件和类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了麻烦,需要一些帮助.我有一个C ++文本经济型太空游戏,我曾经写过,现在我需要用图形和内容创建它的C#版本.但是我还不了解足够的C#来完全重写它.但是有人告诉我,有一种方法可以在C#程序中使用C ++文件和类,这将解决我的问题,直到我学到足够的知识才能完全用C#重写它们.但是这个朋友从未告诉过我该怎么做.这里有人可以帮我还是给我一些好的建议吗?我会很感激的,谢谢.

哦,顺便说一句,我使用的是Microsoft Visual Studio 2008,它是C ++和C#的.net版本.

I''m in a bit of a jam here and need some help. I''ve got a C++ text economic space game that I wrote a while back and I now need to create a C# version of it with graphics and stuff. But I do not know enough C# yet to completely rewrite it. But someone had told me that there is a way to use C++ files and classes in a C# program, and that that would solve my problem until I learned enough to completely rewrite them in C#. But this friend never told me how exactly to do that. Could someone here please help me or give me some good suggestions? I would sure appreciate it, thanks.

Oh, and by the way, I''m using Microsoft Visual Studio 2008 and it''s .net versions of C++ and C#.

推荐答案

实际上简单.
1.如果您的C ++代码是旧的非托管代码,请进行一些必要的修改,以使其与c ++.net代码兼容.
2.用它制作一个dll.
3.只需在新的c#.net项目中添加对该dll的引用.那里的所有代码都可以使用.
Actually it is very simple.
1. If your C++ code is old, unmanaged code, make a few necessary modifications in order for it to complile as c++.net code.
2. Make a dll out of it.
3. Simply add a reference to that dll in your new c#.net project. All of the code there will be accesible for use.


您需要为此使用DLLImport.

请查看此链接: http://stackoverflow.com/questions/772041/using-c-library -in-c [^ ]



> http://stackoverflow.com/questions/569603/using-c-class- dll-in-c-application [ ^ ]
You need to use DLLImport for this.

Please see this link: http://stackoverflow.com/questions/772041/using-c-library-in-c[^]

and

http://stackoverflow.com/questions/569603/using-c-class-dll-in-c-application[^]



看看这些

1)基本P/调用 [ Invoke-declaration-code [ pinvoke-how-to-call-c -from-c/ [ ^ ]
Hi
Have a look on these

1) Essential P/Invoke[^]
2) Invoke-declaration-code[^]
3) pinvoke-how-to-call-c-from-c/[^]


这篇关于如何在C#程序中使用C ++文件和类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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