Skip to content

Instantly share code, notes, and snippets.

@dantheman213
Last active March 20, 2017 17:55
Show Gist options
  • Select an option

  • Save dantheman213/05db88f09ee51d311145a7d2fb014e35 to your computer and use it in GitHub Desktop.

Select an option

Save dantheman213/05db88f09ee51d311145a7d2fb014e35 to your computer and use it in GitHub Desktop.
Marshaling Win32 API Data Types To .NET

Marshaling / Casting Win32 API Data Types To .NET

Referenced here:

https://msdn.microsoft.com/en-us/library/aa719104(v=vs.71).aspx

  • Use ref keyword for inout params
  • Use out keyword for out params
Windows Data Type .NET Data Type
BOOL, BOOLEAN Boolean or Int32
BSTR String
BYTE Byte
CHAR Char
DOUBLE Double
DWORD/LPDWORD Int32 or UInt32
FLOAT Single
HANDLE (and all other handle types, such as HFONT and HMENU) IntPtr, UintPtr, or HandleRef
HRESULT Int32 or UInt32
INT Int32
LANGID Int16 or UInt16
LCID Int32 or UInt32
LONG Int32
LPARAM IntPtr, UintPtr, or Object
LPCSTR String
LPCTSTR String
LPCWSTR String
LPSTR String or StringBuilder
LPTSTR String or StringBuilder
LPWSTR String or StringBuilder
LPVOID IntPtr, UintPtr, or Object
LRESULT IntPtr
SAFEARRAY .NET array type
SHORT Int16
TCHAR Char
UCHAR SByte
UINT Int32 or UInt32
ULONG Int32 or UInt32
VARIANT Object
VARIANT_BOOL Boolean
WCHAR Char
WORD Int16 or UInt16
WPARAM IntPtr, UintPtr, or Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment