Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
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
Posted
Updated 25-Jan-11 19:56pm
v3
Comments
Sergey Alexandrovich Kryukov 26-Jan-11 1:33am    
There is not convert... What if I show you how to export C# library to native code, so you could used it in Visual C++ project, would it help you?
Sandeep Mewara 26-Jan-11 3:48am    
Comment from OP:
sure

Thanks SAKrykow.
How can that be done?
ad-xing 26-Jan-11 4:07am    
???
ARopo 26-Jan-11 6:23am    
You have two options as I see it,

1 Get your C# to register as COM objects then call it from c++ (quite technical at the C++ end and problematic if the c# has user interface.

2 Write all the code in C++ - On the face of it probably the best option.
Sergey Alexandrovich Kryukov 26-Jan-11 14:08pm    
This is yet another option, which many developers though was impossible: direct export of .NET methods to unmanaged. It is allowed with IL. The idea is automatic disassemble of the executable, adjusting some of the method to be exportable and assembling it back.

Never heard of such thing? Me neither, until I read article I reference in my Answer, please see.

--SA

1 solution

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
 
Share this answer
 
v2
Comments
Espen Harlinn 26-Jan-11 15:41pm    
5+ - but what about kudzu's project, if I remember correctly it generates machine code directly - and while I haven't checked it, I wouldn't be surprised if they use the PE format. Just a farfetched thought :)
Sergey Alexandrovich Kryukov 26-Jan-11 15:48pm    
Thank you, Espen.
I'm not sure I saw kudzu's project, could you please give a reference and a note?
--SA
Sergey Alexandrovich Kryukov 26-Jan-11 21:08pm    
I just found Kudzu as an author and have written to him a very warm message about his Article on exceptions -- he is the one who really understand that exceptions are not errors (well, not always, but "not always" already means they are not) -- would you take a look? Pretty interesting I hope.

But I'm interested to know what Article did you mean. -- Please reply.

Thank you.
--SA
Espen Harlinn 27-Jan-11 12:21pm    
COM on Linux - you can even run Word 2007 on Linux: http://appdb.winehq.org/objectManager.php?sClass=version&iId=12811
Wine can be used to run Windows programs on linux, or as a library for building native Linux versions of applications based the Windows code base.
Sergey Alexandrovich Kryukov 27-Jan-11 21:26pm    
Espen,
Not that I'm familiar with those Linux products well (thank you for the link), but you give example where use of COM on Linux can be rationally justified. In the case when your original reason is using .NET assembly in native code, the justification of using such an indirect way as through COM for Linux would be a very poor justification.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900