Saturday, January 08, 2011

From C/C++ to C#, libjpeg/libtiff’s journey from the unmanaged to managed world (Think “Porting code Tips and Tricks”)

CodeProject - Adapting old code to new realities

“This article describes a useful technics for transforming old-style C/C++ code to fully managed C# code. These methods were used for porting classic libjpeg and libtiff libraries to .NET Framework

Table of contents

  • Introduction
  • 1. Prerequisites
  • 2. Transfer process
  • 2.1 Removing the unnecessary code
  • 2.2 Preprocessor and conditional compilation.
  • 2.3 switch and goto operators
  • 2.4 Time to gather stones
  • 2.5 Preprocessor again and multiple inheritance
  • 2.6 typedef operator
  • 2.7. Pointer arithmetic
  • 2.8 Function pointers
  • 2.9 Isolation of the "problem code"
  • 2.10 Changing compiler
  • 2.11 Making it all work

Introduction

In this article I shall describe one of the methods that can be used to transform C/C++ code into C# code with the least amount of effort. The principles laid out in this article are also suitable for other pairs of languages, though. I want to warn you straight-off that this method is not applicable to porting of any GUI-related code.

What is this useful for? For example, I have used this method to port libtiff, the well-known TIFF library, to C# (and libjpeg too). This allowed me to reuse work of many people contributed to libtiff along with the .NET Framework Class Library in my program. Code examples in my article are taken mainly from libtiff / libjpeg libraries.

Adapting old code to new realities - CodeProject…”

I missed this article when it first came out in November, 2010, but better late than never. I liked how it fairly methodically wakes us through the steps the author took in his real world porting of an existing C/C++ code to C#. We’re talking PInvoke, but actual code porting.

(via bitmiracle - Transforming C/C++ code to fully managed C# code.)

No comments: