Marshalling Compiler [ver 0 beta1]

by Martijn Thie [rednael blog]


please report bugs or ask your questions at my blog
please download an example header file here

bool-is-one-byte: when checked a bool will be converted as one byte, otherwise it will be converted as an int (4 bytes).
        (please know that bool and BOOL can be two different types. The C++ type bool in newer versions is 1 byte long.)


Documentation

The Marshalling Compiler takes an C-style header definition as input and compiles that to an import in C# code. It is used to make it easy for coders to use their old C DLLs in their C# projects, but it can be used by anyone who wants to use native DLLs in their C# code.

To use the compiler, just paste the C-style header definition in the textfield above and press the compile button.

This version of the compiler can handle the following: So, when you define a function in the text field above, don't forget to use the extern keyword!

The compiler doesn't know any libraries and other included header files! So, in your input you must have declared it all or you will get a compiler error.
This means that it doesn't recognize:
    LPCSTR
when you didn't include:
    typedef char** LPCSTR;
or:
    #define LPCSTR char**;

You may want to use the following standard definitions:
(just paste it into the header definition field above)

    #define FALSE 0
    #define TRUE 1
    #define CONST const
    typedef unsigned long DWORD;
    typedef int BOOL;
    typedef unsigned char BYTE;
    typedef unsigned short WORD;
    typedef float FLOAT;
    typedef FLOAT *PFLOAT;
    typedef BOOL *PBOOL;
    typedef BOOL *LPBOOL;
    typedef BYTE *PBYTE;
    typedef BYTE *LPBYTE;
    typedef int *PINT;
    typedef int *LPINT;
    typedef WORD *PWORD;
    typedef WORD *LPWORD;
    typedef long *LPLONG;
    typedef DWORD *PDWORD;
    typedef DWORD *LPDWORD;
    typedef void *LPVOID;
    typedef CONST void *LPCVOID;
    typedef int INT;
    typedef unsigned int UINT;
    typedef unsigned int *PUINT;

Also, it can't handle anonymous structures (or enums), nested structures and unions. If you need to nest structures, define them separately and nest them using a reference (a pointer).

Calling conventions and keywords like far and near are also not supported, as they are in a way compiler directives for another compiler. If you do have those keywords into your header definition and you don't want to remove them all,please declare the following definitions:

    #define WINAPI
    #define __stdcall
    #define __cdecl
    #define __pascal
    #define __clrcall
    #define far
    #define near

This current version does not create the code for you which handles the dereferencing of parameters and the casting to the correct types. This will be done in a next version. For now it just creates the imports and defines the types.

Oh and the last thing... in the current version pointers are always 4 bytes (32 bit) long.

Have fun with it...