Skip to content

Commit 46265f2

Browse files
nxtnRon Petrusha
authored andcommitted
Fix platform invoke data types (#11439)
* Fix platform invoke data types * Use code spans * Apply suggestions from code review Co-Authored-By: NextTurn <45985406+NextTurn@users.noreply.github.com> * Win32 APIs -> Windows APIs * Apply suggestions from code review Co-Authored-By: NextTurn <45985406+NextTurn@users.noreply.github.com>
1 parent e4298df commit 46265f2

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

docs/framework/interop/marshaling-data-with-platform-invoke.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@ To call functions exported from an unmanaged library, a .NET Framework applicati
1919

2020
- Substitute managed data types for unmanaged data types.
2121

22-
You can use the documentation supplied with an unmanaged function to construct an equivalent managed prototype by applying the attribute with its optional fields and substituting managed data types for unmanaged types. For instructions about how to apply the **DllImportAttribute**, see [Consuming Unmanaged DLL Functions](../../../docs/framework/interop/consuming-unmanaged-dll-functions.md).
22+
You can use the documentation supplied with an unmanaged function to construct an equivalent managed prototype by applying the attribute with its optional fields and substituting managed data types for unmanaged types. For instructions about how to apply the <xref:System.Runtime,.InteropServices.DllImportAttribute>, see [Consuming Unmanaged DLL Functions](../../../docs/framework/interop/consuming-unmanaged-dll-functions.md).
2323

2424
This section provides samples that demonstrate how to create managed function prototypes for passing arguments to and receiving return values from functions exported by unmanaged libraries. The samples also demonstrate when to use the <xref:System.Runtime.InteropServices.MarshalAsAttribute> attribute and the <xref:System.Runtime.InteropServices.Marshal> class to explicitly marshal data.
2525

2626
## Platform invoke data types
2727

28-
The following table lists data types used in the Win32 API (listed in Wtypes.h) and C-style functions. Many unmanaged libraries contain functions that pass these data types as parameters and return values. The third column lists the corresponding .NET Framework built-in value type or class that you use in managed code. In some cases, you can substitute a type of the same size for the type listed in the table.
28+
The following table lists data types used in the Windows APIs and C-style functions. Many unmanaged libraries contain functions that pass these data types as parameters and return values. The third column lists the corresponding .NET Framework built-in value type or class that you use in managed code. In some cases, you can substitute a type of the same size for the type listed in the table.
2929

30-
|Unmanaged type in Wtypes.h|Unmanaged C language type|Managed type name|Description|
30+
|Unmanaged type in Windows APIs|Unmanaged C language type|Managed type|Description|
3131
|--------------------------------|-------------------------------|------------------------|-----------------|
32-
|**VOID**|**void**|<xref:System.Void?displayProperty=nameWithType>|Applied to a function that does not return a value.|
33-
|**HANDLE**|**void \***|<xref:System.IntPtr?displayProperty=nameWithType> or <xref:System.UIntPtr?displayProperty=nameWithType>|32 bits on 32-bit Windows operating systems, 64 bits on 64-bit Windows operating systems.|
34-
|**BYTE**|**unsigned char**|<xref:System.Byte?displayProperty=nameWithType>|8 bits|
35-
|**SHORT**|**short**|<xref:System.Int16?displayProperty=nameWithType>|16 bits|
36-
|**WORD**|**unsigned short**|<xref:System.UInt16?displayProperty=nameWithType>|16 bits|
37-
|**INT**|**int**|<xref:System.Int32?displayProperty=nameWithType>|32 bits|
38-
|**UINT**|**unsigned int**|<xref:System.UInt32?displayProperty=nameWithType>|32 bits|
39-
|**LONG**|**long**|<xref:System.Int32?displayProperty=nameWithType>|32 bits|
40-
|**BOOL**|**long**|<xref:System.Boolean?displayProperty=nameWithType> or <xref:System.Int32?displayProperty=nameWithType>|32 bits|
41-
|**DWORD**|**unsigned long**|<xref:System.UInt32?displayProperty=nameWithType>|32 bits|
42-
|**ULONG**|**unsigned long**|<xref:System.UInt32?displayProperty=nameWithType>|32 bits|
43-
|**CHAR**|**char**|<xref:System.Char?displayProperty=nameWithType>|Decorate with ANSI.|
44-
|**WCHAR**|**wchar_t**|<xref:System.Char?displayProperty=nameWithType>|Decorate with Unicode.|
45-
|**LPSTR**|**char &ast;**|<xref:System.String?displayProperty=nameWithType> or <xref:System.Text.StringBuilder?displayProperty=nameWithType>|Decorate with ANSI.|
46-
|**LPCSTR**|**const char &ast;**|<xref:System.String?displayProperty=nameWithType> or <xref:System.Text.StringBuilder?displayProperty=nameWithType>|Decorate with ANSI.|
47-
|**LPWSTR**|**wchar_t &ast;**|<xref:System.String?displayProperty=nameWithType> or <xref:System.Text.StringBuilder?displayProperty=nameWithType>|Decorate with Unicode.|
48-
|**LPCWSTR**|**const wchar_t &ast;**|<xref:System.String?displayProperty=nameWithType> or <xref:System.Text.StringBuilder?displayProperty=nameWithType>|Decorate with Unicode.|
49-
|**FLOAT**|**float**|<xref:System.Single?displayProperty=nameWithType>|32 bits|
50-
|**DOUBLE**|**double**|<xref:System.Double?displayProperty=nameWithType>|64 bits|
51-
52-
For corresponding types in [!INCLUDE[vbprvblong](../../../includes/vbprvblong-md.md)], C#, and C++, see the [Introduction to the .NET Framework Class Library](../../../docs/standard/class-library-overview.md).
32+
|`VOID`|`void`|<xref:System.Void?displayProperty=nameWithType>|Applied to a function that does not return a value.|
33+
|`HANDLE`|`void *`|<xref:System.IntPtr?displayProperty=nameWithType> or <xref:System.UIntPtr?displayProperty=nameWithType>|32 bits on 32-bit Windows operating systems, 64 bits on 64-bit Windows operating systems.|
34+
|`BYTE`|`unsigned char`|<xref:System.Byte?displayProperty=nameWithType>|8 bits|
35+
|`SHORT`|`short`|<xref:System.Int16?displayProperty=nameWithType>|16 bits|
36+
|`WORD`|`unsigned short`|<xref:System.UInt16?displayProperty=nameWithType>|16 bits|
37+
|`INT`|`int`|<xref:System.Int32?displayProperty=nameWithType>|32 bits|
38+
|`UINT`|`unsigned int`|<xref:System.UInt32?displayProperty=nameWithType>|32 bits|
39+
|`LONG`|`long`|<xref:System.Int32?displayProperty=nameWithType>|32 bits|
40+
|`BOOL`|`long`|<xref:System.Boolean?displayProperty=nameWithType> or <xref:System.Int32?displayProperty=nameWithType>|32 bits|
41+
|`DWORD`|`unsigned long`|<xref:System.UInt32?displayProperty=nameWithType>|32 bits|
42+
|`ULONG`|`unsigned long`|<xref:System.UInt32?displayProperty=nameWithType>|32 bits|
43+
|`CHAR`|`char`|<xref:System.Char?displayProperty=nameWithType>|Decorate with ANSI.|
44+
|`WCHAR`|`wchar_t`|<xref:System.Char?displayProperty=nameWithType>|Decorate with Unicode.|
45+
|`LPSTR`|`char *`|<xref:System.String?displayProperty=nameWithType> or <xref:System.Text.StringBuilder?displayProperty=nameWithType>|Decorate with ANSI.|
46+
|`LPCSTR`|`const char *`|<xref:System.String?displayProperty=nameWithType> or <xref:System.Text.StringBuilder?displayProperty=nameWithType>|Decorate with ANSI.|
47+
|`LPWSTR`|`wchar_t *`|<xref:System.String?displayProperty=nameWithType> or <xref:System.Text.StringBuilder?displayProperty=nameWithType>|Decorate with Unicode.|
48+
|`LPCWSTR`|`const wchar_t *`|<xref:System.String?displayProperty=nameWithType> or <xref:System.Text.StringBuilder?displayProperty=nameWithType>|Decorate with Unicode.|
49+
|`FLOAT`|`float`|<xref:System.Single?displayProperty=nameWithType>|32 bits|
50+
|`DOUBLE`|`double`|<xref:System.Double?displayProperty=nameWithType>|64 bits|
51+
52+
For corresponding types in Visual Basic, C#, and C++, see the [Introduction to the .NET Framework Class Library](../../standard/class-library-overview.md#system-namespace).
5353

5454
## PinvokeLib.dll
5555

docs/standard/native-interop/best-practices.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Don't forget that `GCHandle` needs to be explicitly freed to avoid memory leaks.
156156

157157
## Common Windows data types
158158

159-
Here is a list of data types commonly used in Win32 APIs and which C# types to use when calling into the Win32 code.
159+
Here is a list of data types commonly used in Windows APIs and which C# types to use when calling into the Windows code.
160160

161161
The following types are the same size on 32-bit and 64-bit Windows, despite their names.
162162

0 commit comments

Comments
 (0)