convert C++ to C# or using managed C++ with VB.Net

G

Guest

I have legacy DLL code written in C++ that is essentially C code, an
implementation of a set of formulas used in our industry. There are no DB or
GUI interfaces, just exposed methods. I would like to convert it to C# and
if that is not possible to manage C++. I want to use the DLL in a larger
VB.Net program.
Is there a tool that will convert C++ to C#?
Are there any articles/papers/examples on converting C++ to C#?
Are there any articles/papers/examples using managed C++ with VB.Net?
Thank You,
 
T

TerryFei

Hi Mike,
Welcome to MSDN Newsgroup!

As far as I known, there is no tool, which could convert C++/C code to C#
automatically. If we want to use legacy dll in .Net program, we could use
P/Invoke or Interoper mechanism to achieve the goal.
1. If the dll is a legacy dll(not belongs to COM type), we could use
P/Invoke to use it in .Net program. You could refer to the following
articles,
Title: Calling Win32 DLLs in C# with P/Invoke
URL: http://msdn.microsoft.com/msdnmag/issues/03/07/NET/

Title: Using Platform Invoke
URL: http://www.codeproject.com/dotnet/PInvoke.asp


2. If the dll belongs to COM type, we recommend you use Interoperability
mechanism. I browse some articles from internet and hope it's helpful for
you.
Title: .NET - COM Interoperability
URL:http://www.codeproject.com/dotnet/COM_DOTNET_INTEROP.asp

Title: Understanding Classic COM Interoperability With .NET Applications
URL:http://www.codeproject.com/dotnet/cominterop.asp#QueryInterface


I hope the above information is useful for you. If there is any question,
please feel free to join the community and we are here to support you at
your convenience. Thanks again and have a nice day.

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
T

TerryFei

Hi Mike,

I just wanted to check how things are going and whether or not your
problem has been resolved.

If there is any question, please feel free to let me know. Thanks!

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Terry
--
Thank you for your help. I am follicular P/Invoke I used it back when I
wrote my first VB.Net program to connect to the serial ports. It looks like
this is more completed than I though. I was look for a quick fix to give use
some time. The only redeeming quality for the code we have is it works;
which is worth something. We need to rewrite it any way manly because of all
the hard coded constants in the formulas that need to be moved to a database.

Thank you again.
 
T

TerryFei

Hi Mike,

You are welcome. :)
Thanks for participating the community.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
R

Richard Grimes

Michael said:
I have legacy DLL code written in C++ that is essentially C code, an
implementation of a set of formulas used in our industry. There are
no DB or GUI interfaces, just exposed methods. I would like to
convert it to C# and if that is not possible to manage C++. I want
to use the DLL in a larger VB.Net program.
Is there a tool that will convert C++ to C#?

To be honest I would not recommend this. This is porting, and porting
creates ported code. Think about it. Your DLL has been written for the
unmanaged world by C++ experts with all of their understanding about
Win32 and the unmanaged world. The DLL has been code reviewed by Win32
experts. The DLL has been tested, tuned and debugged in the unmanaged
world, and presumably it has been used as a released product in the
unmanaged world. Don't you think that the best thing to do is to keep it
running in the unmanaged world?

If there are serious flaws, or if you plan to do substancially extend
the library, then there may be a good reason to write the code in C#.
But porting the code to C# or managed C++ IMO is not a great idea.
Instead use platform invoke so that the code will run in the unmanaged
world where it was designed to run and where it was tested and tuned.
Are there any articles/papers/examples on converting C++ to C#?

Not really, but in any case you should regard the process as being a
convertion from Win32 code to .NET code. There are large differences
between the two environments, and those differences are not necessarily
obvious in the differences between the two languages. At first sight C#
just appears to be a simplified version of C++ with some VB-isms added.
For example, C# has 'destructors' or at least it has a feature that uses
the C++ syntax for a destructor. However, it is NOT a C# destructor, and
behaves in a totally different way to a C++ destructor.
Are there any articles/papers/examples using managed C++ with VB.Net?

It does not matter. Managed C++ produces .NET assemblies. The code using
those assembies should not care what language was used to create the
assembly. And there *should* not be any artifacts in the assembly from
the language used to create it.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top