 |
P/Invoke Wizard Home
|
The PInvoke Wizard |
| |
| PInvoke Wizard Examples |
| 2. Example: Data Structures |
|
Here is an example of a PInvoke conversion. In this example, a data structure is defined in an include file using the typedef struct keywords:
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
|
With a mouse click, the following C# declaration is created:
// [C#] output: managed code declarations
[StructLayout(LayoutKind.Sequential,Pack=4)]
public struct RECT
{
public Int32 left;
public Int32 top;
public Int32 right;
public Int32 bottom;
};
|
This is a little more time consuming than simple constants. And sure, you could do it yourself. It might take you five minutes to do this one. Multiply this by a few dozen (or even a hundred), and you have a task that might risk putting your already tight schedule at risk. Why take a chance, when this tool can do all the work for you?
For the above C/C++ declaration, the PInvoke Wizard generates the VB.NET declarations shown below:
Public Structure RECT
Public left As Int32
Public top As Int32
Public right As Int32
Public bottom As Int32
End Structure
|
|
|
Last updated: October 25, 2023 By: Paul Yao The Paul Yao Company
|
|
|
|