下表列出 Win32 API (Wtypes.h) 與 C 風格函數常用資料類型,以及對應的 .NET 內建值類型/類別。第三欄為托管代碼對應類型,某些情況可用大小相同的類型替代。
| Wtypes.h 非托管類型 | 非托管 C 型別 | 托管類型 | 說明 |
|---|---|---|---|
| handle | void* | System.IntPtr | 32 位元 |
| byte | unsigned char | System.Byte | 8 位元 |
| short | short | System.Int16 | 16 位元 |
| Word | unsigned short | System.UInt16 | 16 位元 |
| int | int | System.Int32 | 32 位元 |
| uint | unsigned int | System.UInt32 | 32 位元 |
| long | long | System.Int32 | 32 位元 (Win32 long 為 32 位) |
| bool | long | System.Int32 | 32 位元 (Win32 BOOL 為 4 位元組) |
| dWord | unsigned long | System.UInt32 | 32 位元 |
| ulong | unsigned long | System.UInt32 | 32 位元 |
| char | char | System.Char | 需加 MarshalAs(UnmanagedType.U1) 或 ANSI 修飾 |
| lpstr | char* | System.String / StringBuilder | ANSI 字串指標 |
| lpcstr | const char* | System.String / StringBuilder | ANSI 常數字串指標 |
| lpwstr | wchar_t* | System.String / StringBuilder | Unicode 字串指標 |
| lpcwstr | const wchar_t* | System.String / StringBuilder | Unicode 常數字串指標 |
| float | float | System.Single | 32 位元 |
| double | double | System.Double | 64 位元 |
DllImport) 時務必對應正確 MarshalAs 屬性,特別是字串與布林型別。IntPtr 用於指標/控制代碼,32/64 位元自動適配。long 與 BOOL 均為 32 位元,對應 Int32,切勿誤用 Int64。