Win32 APIS to .NET

25. October 2006 03:47 by Mrojas in General  //  Tags:   //   Comments (0)
 Migrating C++ code from Win32 to managed code can be quite complex, specially if you have a lot of Win32 code of GUI code.
I copying some links here that will be of help during this task

The following link gives an introduction to managed C++:

Introduction to Managed C++

From that article:

Here are some specific advantages of MC++:

  • The best performance of generated IL code because of both optimizations of the generated IL and less IL generated (as discussed in the previous section). This is specifically because MC++ is the only .NET compiler with a full optimizer back end, which is pretty much the same one that is used by the unmanaged compiler.
  • MC++ is your language of choice if you want full control of the .NET environment:
    • Allows one to use all seven levels of CTS member access. C# allows only six.
    • Allows direct access to interior gc pointers, useful in a whole class of system applications such as system and .NET utilities.
    • Offers explicit control of expensive operations like boxing.
    • Supports multiple indexed properties on a type, unlike C#.
  • MC++ is currently the only managed language that allows you to mix unmanaged and managed code, even in the same file. This leads to several other points:
    • Allows a developer to keep performance-critical portions of the code in native code.
    • Gives seamless access to all unmanaged libraries, such as DLLs, statically-linked libraries, COM objects, template libraries, and more.
    • Leverages existing investments in C++ programming skills and legacy C++ code.
    • Porting unmanaged code to .NET: MC++ allows you to take existing unmanaged code and compile it to managed code (with the /clr compiler switch and IJW).
    • Gives the ability to port code at one's own rate rather than re-write all at once.
    • Provides the easiest way to add .NET support to your existing native C++ Windows applications, by allowing you to bridge the gap between the two environments with as little work on your behalf as possible, and with the lowest performance penalty.
  • MC++ is currently the only language that allows some form of multi-paradigm design and development with full support for generic programming and templates. This can lead to more options and better designs and implementations.

Disadvantages of Managed C++

  • C++ is a more complex language than C# in both its syntax and areas where one could get into trouble. Since MC++ follows the C++ paradigm of "explicit is good", some MC++ constructs may seem really ugly. For simpler types of applications, and with certain types of developers, it may make more sense to use C#.
  • Managed C++ code is non-verifiable, since C++ can perform unsafe operations. The implication of this is that MC++ code may not run in restricted environments that will not run code that is non-verifiable.
  • Some minor features of the .NET platform are not supported yet, such as Jagged Arrays.
  • IDEsupport is currently lacking, compared to other managed languages, since there's little or no designer support (but Everett will change this).
  • "
#using mscorlib.dll;
// required for MC++
void main()
    System::Console::WriteLine(S"Managed C++ Rocks!!");

This other article explains how the different mixes you can make with managed and unmanaged code:
Intro to C++ Managed Code

And this article Microsoft Win32 to Microsoft .NET Framework API Map
Gives a map for your APIs that can be very helpful