Unmanaged c++ project to managed

Nov 6, 2011 at 12:48pm
Hello all,

i got a shared unmanaged c++ project
and i need to migrate it to .net

What is the best way of doing so ?

The final result should be that i will be able a COM reference of the c++ project to my .net project.

Thanks
Nov 6, 2011 at 1:44pm
Is the unmanaged C++ project a dll? Or an exe?

You can mix managed and unmanaged C++ in the same module, so you could leave most of the code alone and just provide a managed interface class (or classes, depending on what functionality you need to expose).

But I don't get the comment about COM. If you've implemented a .Net interface for your dll, you can use .Net's standard assembly-based mechanism.

COM would be relevant if you want to leave the dll as unmanaged C++ and provide a COM interface. The .Net application could then access it's functionality via .Net's COM interop mechanism.

Is it that you are you wondering about which of these approaches to use?

Andy
Nov 6, 2011 at 2:26pm
Thank for the response,

the unmanaged project is an exe.

Forget my comment about the COM part,

"You can mix managed and unmanaged C++ in the same module, so you could leave most of the code alone and just provide a managed interface class (or classes, depending on what functionality you need to expose)."

How can this be done ? If i will do so , will i be able to add reference to this managed class from a .net project ?

Thanks
Nov 6, 2011 at 2:50pm
When compiling with /clr you can use #pragma unmanaged / #pragma managed to control how different regions of the code are treated.
http://msdn.microsoft.com/en-us/library/0adb9zxe%28v=VS.90%29.aspx

When it's build with /clr, you will be able to access the managed class. But if it's an exe, written in WIN32/MFC, and you're talking about migrating to use WinForms/..., I think it's quite a different matter.

What is the reason for the migration? To access some functionality? Or??

Andy

PS Also see "Initialization of Mixed Assemblies", if you're going to ix and match.
http://msdn.microsoft.com/en-us/library/ms173266%28v=VS.90%29.aspx


Last edited on Nov 6, 2011 at 4:16pm
Nov 6, 2011 at 2:54pm
I want to use the code's API in WPF application,

what do you think is the best approach for me ?

The native c++ code should be cross platforms
so .net developer/IPhone/etc.. will be able to use this code

the ideal is that if one change the c++ code it wont drag changes to the other platforms who use the code
Nov 6, 2011 at 3:50pm
You are talking about non-GUI code, yes? If so, you should be able to share the bulk of the C++.
Nov 6, 2011 at 4:12pm
Yes, non Gui
How to share it ?
Nov 6, 2011 at 4:19pm
Write a managed interface class which calls through to the unmanaged code.

If you are unsure of how to do this, the first thing you should do is read some of various forum's discussions about the subject. Tru ggogling for "managed wrapper for unmanaged c++"

Topic archived. No new replies allowed.