C to C#

  • Thread starter Thread starter Development at American Savings
  • Start date Start date
D

Development at American Savings

Anyone know of a good tutorial on how to take some pretty complicated C code
and turn it into a C# class?

I work for a company that wants to begin developing in .net languages but we
have a whole bunch of very old, very complex c functions that I would very
much like to turn into a DLL (as I'm sure all of you do) but the truth is I
have no idea where to get started.

Any pointers would be greatly appreciated.
 
Development said:
Anyone know of a good tutorial on how to take some pretty complicated C code
and turn it into a C# class?

I work for a company that wants to begin developing in .net languages but we
have a whole bunch of very old, very complex c functions that I would very
much like to turn into a DLL (as I'm sure all of you do) but the truth is I
have no idea where to get started.

I am not sure it would pay to convert old source codes. Why not make
C(++) dlls out of them and writing a C# library which encapsulates these
functions via PInvoke?
By the way: C and C# usually have very different application areas so it
seldom is useful to convert C projects: C# is mostly (and best) used for
desktop and web applications.
 
This is a good idea but would require some porting of the C code to make it
compile. An alternative method that has worked well for me is to leave the C
code alone (move it into a standard DLL or treat it as a library) and create
a Managed C++ DLL Wrapper. The wrapper can expose the functionality from the
C library/DLL easily to the C# layer as needed and provides a shim that can
allow gradual porting of the C code to Managed C++. Or the functionality
could gradually be migrated into C# over time while still deriving benefit
from the existing C code in production.

Jon Davis said:
A better method than P/Invoke encapsulation is to recompile the C code with
Managed Extensions enabled. This will cause the DLL to be loaded into the
.NET runtime and, with some adjustments, each of its members can be exposed
to C# automatically.

Please look at C++ NET.
http://msdn.microsoft.com/msdnmag/issues/01/07/vsnet/default.aspx

Jon


C
 

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

Back
Top