dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]InternalCall or: how to call system libs


From: Rhys Weatherley
Subject: Re: [DotGNU]InternalCall or: how to call system libs
Date: Wed, 03 Apr 2002 14:07:58 +1000

Gopal Vijayaraghava Menon wrote:

> Please put all the native calls into a single file and mail me that,
> I'll try to wrap it and make a DLL . [...]

That brings to mind an idea I had for a project a while ago.
Someone may want to volunteer to look into this.

It would be nifty if there was a way to bulk-convert a .h
file into an assembly that has all of the necessary PInvoke
stuff in place to provide C# access to the library.

It would work as follows:

1. Parse the .h file using a mini-C parser (doesn't need
   to be too complicated, as it only cares about prototypes).
2. For each function, output the necessary ilasm code for
   PInvoke access.
3. For each major struct and typedef, generate a ValueType
   that contains the same fields and information.
4. Pass the final IL assembly file through "ilasm" to make
   the assembly.

It may not work on all API's - some are just too complex
to decode into IL-compatible declarations.  But it would
take the pain out of the most common cases.

The process can be simplified somewhat by using GNU's
"cpp" to do the C pre-processor bits, and by dusting off
one of the ANSI C yacc grammars that are floating around
the net.

Since you don't care about function bodies, only declarations,
a lot of the complexity of C can be factored out and ignored.
Treecc can help manage the remaining complexity.

If anyone is interested in pursuing this, then let me know.

Cheers,

Rhys.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]