Monday, November 28, 2005

"The P/Invoke Wizard"

The P/Invoke Wizard

"What is the P/Invoke Wizard?

I wrote the P/Invoke Wizard to save time for both myself and my co-author, David Durant, while we were writing our .NET Compact Framework books. I wrote this tool because I found that P/Invoke declarations were both tedious and error prone when done by hand. Now with a few clicks of my mouse, I get complete and correct declarations in a fraction of the time it previously took. My company started selling the P/Invoke Wizard in 2002. Since finishing my books, I have been able to make some time to update the tool - and now version 1.3 is available.

The P/Invoke Wizard is a tool that automates the process of writing declarations in managed code for calling into unmanaged DLLs. With just a few mouse clicks, the P/Invoke Wizard can opens a C or C++ include file and create thousands of .NET-compatible P/Invoke declarations in a choice of C# or Visual Basic .NET. The wizard can be set for compatibility with either the .NET Compact Framework or the .NET Framework.

...

How Does The P/Invoke Wizard Work?

P/Invoke works by reading C/C++ include (.H) files. The P/Invoke processing engine takes the various declarations and produces a compatible .NET version in your choice of C# or Visual Basic .NET.

P/Invoke understands the following kinds of C/C++ declarations:

#define statements for integer and string constants
enum statements that define enumerated constant values
typedef struct declarations that define the layout of structures
typedef declarations for custom data types
union statements
function prototypes

The P/Invoke Wizard converts #define constants into the equivalent C# or VB.NET declarations. It converts C/C++ data structure definitions and converts them into the equivalent .NET data structures. It also reads C/C++ function prototypes and generates the equivalent function.

...

P/Invoke Wizard Limitations

Version 1.3 of the P/Invoke Wizard relies on information found in include (*.H) files. So if you do not have the include file, then P/Invoke cannot help you. It does not, for example, use the binary DLL file for input. Nor does the P/Invoke Wizard use a COM Type Library. In short, you need include (*.h) file declarations. Another limitation is that this tool does not accept executable C++ statements -- function calls, loops, etc.

What it *does* provide is a shortcut when you have a lot of native code declarations that you need to access from managed code. ...."


This $59.95 tool sounds interesting. I downloaded the demo and pointed it at a couple *.H files and it seemed to translate them with no problems. The next time I need to do some header file translations, I'm checking this utility out in detail...

(via pinvoke.net: Helpful Tools (misc))

No comments: