在c#中使用c/c ++函数 [英] use c/c++ functions in c#

查看:87
本文介绍了在c#中使用c/c ++函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我最近下载了c/c ++算法,我具有c ++的完整源代码.
我想在c#中调用c程序的功能,

我读了很多有关此的文章,但是您能告诉我如何在c ++中将源代码编译为DLL.

还是我可以在C#中使用该程序??

Prathamesh

Hi,
I recently downloaded a c/c++ algorithm, i have complete source code in c++.
I want to invoke the functions of c program in c#,

I read many articles about this, but can you tell how can I compile source into DLL in c++.

or is there any i can use the program in c#??

Prathamesh

推荐答案

最简单的方法是将其编译为dll.假设您没有使用VS的Express版本,请在解决方案中确定一个新项目,然后选择其他语言","Visual C ++",然后根据您的原始来源选择"MFC DLL"或类库"要求.

一旦构建了DLL,您就应该能够使用DllImport从C#调用函数.
The easiest way is to compile it to a dll. Assuming you aren''t using the Express edition of VS, cerate a new project within your solution, and select "Other languages", "Visual C++", then either choose "MFC DLL" or "Class Library" depending on your original source requirements.

Once you build the DLL you should be able to invoke the functions from C#, using DllImport


要在VS中创建DLL,您可以参考此处

http://msdn.microsoft.com/en-us/library/ms235636 (v = vs.80).aspx [ http://msdn.microsoft.com/en-us/library/aa288468%28v = vs.71%29.aspx [ ^ ]
For creating DLL in VS you can refer here

http://msdn.microsoft.com/en-us/library/ms235636(v=vs.80).aspx[^]

And for calling these DLL functions in C# you can use p-invoke. Check here for more info

http://msdn.microsoft.com/en-us/library/aa288468%28v=vs.71%29.aspx[^]


有很多C#到Cpp转换器可用
试试这个软件转换器
快乐编程:-)
There are a lot of C# to Cpp Convertors available
try this Software Convertor
Happy Programming:-)


这篇关于在c#中使用c/c ++函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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