 |
P/Invoke Wizard Home
|
The PInvoke Wizard |
| |
| PInvoke Wizard Examples |
| 3. Example: Function Calls |
|
Here is an example of a PInvoke conversion. In this example, the PInvoke Wizard converts a function call, which is shown here as it might appear in an include file:
WINBASEAPI
DWORD
WINAPI
GetTempPathW(
DWORD nBufferLength,
LPWSTR lpBuffer);
|
For function calls, you need to include the name of the target DLL in your PInvoke declaration. You also need to specify the correct number and type of parameters. Here is the C# definition:
// [C#] output: managed code declarations
[DllImport("kernel32.dll")]
public static extern Int32 GetTempPathW (UInt32 nBufferLength, String lpBuffer);
|
In most cases, the function call declarations are the things you really need.
You may or may not need all of the supporting symbolic constants.
You will, on the other hand, need to include all of the parameters for each of the functions that you need.
Whether you need to convert just a dozen or a few hundred, the PInvoke Wizard will generate all of the declarations that you need --
quickly and accurately.
Save your time and energy so that you don't have to work weekends. (Although, we admit, sometimes it IS fun to hang around the office on the weekend. Just not EVERY weekend!)
For the above C/C++ declaration, the PInvoke Wizard generates the VB.NET declarations shown below:
<DllImport("kernel32.dll")> _
Public Shared Function GetTempPathW ( _
ByVal nBufferLength As UInt32 _
, ByVal lpBuffer As String _
) As Int32
End Function
|
|
|
Last updated: October 25, 2023 By: Paul Yao The Paul Yao Company
|
|
|
|