可以将C#转换为C ++ 6吗? [英] Can convert C# to C++ 6?

查看:95
本文介绍了可以将C#转换为C ++ 6吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



急需帮助

网站: http://www.smileymicros.com/index.php?module= pagemaster& PAGE_user_op = view_page& PAGE_id = 50

在上述网站上,我被要求以虚拟串行端口-最终学年项目的简单终端作为新加坡的全日制学生使用.

但是要求需要我在Visual C ++ 6上工作,是否可以通过C#下的简单终端将其转换为Visual C ++ 6或任何可以将其转换为Visual C ++ 6,MFC格式的人?
项目类型:dsw(工作区).

紧急情况需要尽快完成,因为我目前有20天时间来解决此问题.

问候,
david

Hi,

Need help badly

website: http://www.smileymicros.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=50

On the above mentioned website, I was required the use of the Virtual Serial Port - Simple Terminal for Final Year Project as a Full-Time Student in Singapore.

But the requirements needs me to work on Visual C++ 6, is it possible with the Simple Terminal under C# to convert into Visual C++ 6 or anyone out there can do into Visual C++ 6, MFC Format?
Project type: dsw (workspace).

Urgent need this to be done asap as I currently left 20 days to solve this problem.

Regards,
david

推荐答案

重新编写C ++已有的功能可能很乏味且毫无意义.为与.NET捆绑在一起的库已经提供的代码寻找C ++替换(甚至重写)也很困难.所有这些都可能挑战项目的可行性.

可行的选项可以使用.NET,但可以将某些功能导出到不受管理的状态,以供C ++项目使用.正如ad-xing对这种选择感兴趣的时候,我将提供一些细节.通常,常规方法是在.NET端实现COM组件.

COM存在某些问题.我并不感到惊讶,ARopo表示,甚至完全重写C ++中的代码也可能是更好的选择.
该技术正在逐渐过时.主要问题是开销.特别是,通常它需要在系统注册表中注册组件-注册表污染的主要来源之一. .NET和Microsoft试图摆脱这种局面,转而采用本地方法来实现组件依赖关系和版本控制.而且,COM方法几乎不适用于Unix(带有Mono或其他产品).
考虑到所有这些,从托管程序集直接导出到非托管可执行文件将非常有吸引力.但是该怎么做呢?

更好的解决方案是在允许此类导出的地方使用IL.有一个实用程序可以根据可用的.NET项目自动执行此操作.

这是我尝试过的最好方法:

Emilio Reale的非托管代码可以包装托管方法",2004年8月29日.

另请参见:如何将.NET功能自动导出到非托管程序中",Selvin,2006年11月22日 ,以及:用于不受管理的出口的C#项目模板",作者:Robert Giesecke,2010年1月11日.

另外,查看我不久前发布的类似主题的其他答案可能会有所帮助:
在MFC中加载C#DLL [
Re-writing already available functionality to C++ may be to tedious and make little sense. Finding C++ replacement (or even re-writing) for codes already provided by the libraries bundled with .NET can also be very hard. All this can challenge the very feasibility of the projects.

The viable option can be using .NET but exporting some of the functionality to unmanaged to be used by a C++ project. As ad-xing expressed interest in such option, I''ll provide some detail. Usually a regular way to do this is implementation of COM component on .NET side.

There are certain problems with COM. I''m not too surprised ARopo commented that even total re-writing the code in C++ could be a better option.
The technology is gradually becoming obsolete. Main problem is overhead. In particular, normally it requires registration of a component in the system registry -- one of the major sources of registry contamination. .NET and Microsoft are trying to go away from such things in favor of local approach to component dependency and versioning. Also, COM approach will hardly be available for Unix (with Mono or other product).
In view of all that, a direct export from managed assembly to the unmanaged executable would be quite attractive. But how to do this?

A better solution is using IL where such export is allowed. There is a utility which helps to do it automatically based on available .NET project.

This is the best method I tried:

"Unmanaged code can wrap managed methods" by Emilio Reale, 29 Aug 2004.

See also this: "How to Automate Exporting .NET Function to Unmanaged Programs" by Selvin, 22 Nov 2006, and this: "C# Project Template for Unmanaged Exports" by Robert Giesecke, Jan 11, 2010.

Also, it may be helpful to look in my other Answer on a similar topic I''ve posted a while ago:
loading C# DLL in MFC[^] where you can find some matter on motivation of such approach and useful discussion.

Dealing with .NET to C++ interoperability requires good understanding of both. However, it''s not so hard if exported methods are limited to the use of primitive types and the types known to default Marshall methods, such as string to PCHAR or PWCHAR, etc. Anyway, learning of all that matter should be faster than re-writing of a big library.

Further questions are welcome.
Good luck!
—SA


这篇关于可以将C#转换为C ++ 6吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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