473,804 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7059
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 Interoperabilit y
mechanism. I browse some articles from internet and hope it's helpful for
you.
Title: .NET - COM Interoperabilit y
URL:http://www.codeproject.com/dotnet/CO...ET_INTEROP.asp

Title: Understanding Classic COM Interoperabilit y 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
51737
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 have some legcay C code that needs to process a string taken from a textbox, then I need to re-display the string as the textbox->Text. I easily found how to convert from system::string to char but I can't figure out how to go the other way!!
7
1945
by: ±èº´¼®\( Kevin Kim \) | last post by:
Hi all __gc class Test { }; void Temp( void ) { Test *pTest = new Test;
3
18281
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
7568
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. Also, I was wondering could there be issues in not making copies when converting??? I was thinking, when "pointing" to the same data with both managed and unmanaged strings/arrays couldn't there be issues such as the garbage collector trying to...
2
2342
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 = myFile->get_Length(); Byte myFileData; myFile1Data = new Byte;
3
5634
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 func(char c). How to convert from String *s to char *c? thanks Keith
1
2420
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
2900
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 will call. I'm getting Error 2664: cannot convert parameter 1 from CallBack __gc * to CUSTOM_HOOK_CALLBACK_FUNCTION. Here's what I have... In my unmanaged DLL -- Header file: --------------------------------------------------- typedef VOID...
5
6350
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 complicated. Or maybe there is a managed wrapper class for safe array? Thanks in advance.
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10569
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.