473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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,
--
Mike Reed
Nov 22 '05 #1
5 7034
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/CO...ET_INTEROP.asp

Title: Understanding Classic COM Interoperability With .NET Applications
URL:http://www.codeproject.com/dotnet/co...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.)

Nov 22 '05 #2
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.)

Nov 22 '05 #3
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.
--
Mike Reed
""TerryFei"" wrote:
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.)

Nov 22 '05 #4
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.)

Nov 22 '05 #5
Michael D. Reed wrote:
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
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Trep | last post by:
Hi there! I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003. This is necessary because I...
7
by: ±èº´¼®\( Kevin Kim \) | last post by:
Hi all __gc class Test { }; void Temp( void ) { Test *pTest = new Test;
3
by: James | last post by:
Has anyone written a utility to convert a C# form to C++.net? i.e. to convert "using System.Data" to "using namespace System::Data" etc
7
by: Bob Rock | last post by:
Hello, converting from the managed to the unmanaged world (and viceversa strings) and byte arrays is something I do often and I'd like to identify the most correct and efficient way to do it....
2
by: Howard Weiss | last post by:
I am reading a file (containing short integers). To read the file, I use the following FileStream *myFile = new FileStream(FileName, FileMode::Open, FileAccess::Read); __int64 myFileSize =...
3
by: keith | last post by:
In managed C++, there is variable String *s. The variable got value from a C# assembly. Then I need to convert it into char *c in order to call an external function in a dll that accepts parameter...
1
by: yaron | last post by:
Hi, my unmanaged method return void* pointer to my managed c++ wrapper class. How do i convert this pointer to a managed object so that a c# client could use it ? Thanks.
1
by: stillh2os | last post by:
Hello. I'm new to .NET, and I'm trying to implement a callback function. I want my managed C++ code to call an unmanaged function, passing in a callback function that the unmanaged C/C++ code...
5
by: Maxim | last post by:
Hi all, I'm calling a COM Interface method that returnes SafeArray wrapped into variant. Is it possible to convert it to managed array? Because working with SAFEARRAY directly is a bit...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.