WinTypes
This package makes it easier/quicker/more convenient to translate Windows API function from Julia and also improves readability with respect to the original function definitions in the Windows API.
Installation
pkg> add WinTypes
Usage & Examples
Here's an example comparing calling Windows API functions with and without WinTypes
:
With WinTypes
a Windows API call would look something like:
using WinTypes: HANDLE, DWORD, BOOL
function get_console_mode()
STD_OUTPUT_HANDLE = -11
hOutput = ccall(:GetStdHandle, stdcall, HANDLE, (DWORD,), STD_OUTPUT_HANDLE % DWORD)
dwMode = Ref{DWORD}()
ccall(:GetConsoleMode, stdcall, BOOL, (HANDLE, Ref{DWORD}), hOutput, dwMode)
return dwMode[]
end
Now, compare this to the call without this package:
function get_console_mode()
STD_OUTPUT_HANDLE = -11
hOutput = ccall(:GetStdHandle, stdcall, Ptr{Cvoid}, (UInt32,), STD_OUTPUT_HANDLE % UInt32)
dwMode = Ref{UInt32}()
ccall(:GetConsoleMode, stdcall, Int32, (Ref{Cvoid}, Ref{UInt32}), hOutput, dwMode)
return dwMode[]
end
Finally, here are the corresponding Windows API function syntax definitions in C
:
HANDLE WINAPI GetStdHandle(
_In_ DWORD nStdHandle
);
BOOL WINAPI GetConsoleMode(
_In_ HANDLE hConsoleHandle,
_Out_ LPDWORD lpMode
);
As you can see, the call to these APIs using WinTypes
is easier to translate and directly translatable without manually looking up the myriad Windows data types.
Alias List
The following aliases are defined:
FALSE = Cint(0)
TRUE = Cint(1)
BOOL = Cint
BOOLEAN = BYTE
BYTE = Cuchar
CCHAR = Cchar
CHAR = Cchar
COLORREF = DWORD
DWORD = Culong
DWORDLONG = UInt64
DWORD32 = UInt32
DWORD64 = UInt64
FLOAT = Cfloat
HACCEL = HANDLE
HANDLE = Ptr{Cvoid}
HBITMAP = HANDLE
HBRUSH = HANDLE
HCOLORSPACE = HANDLE
HCONV = HANDLE
HCONVLIST = HANDLE
HCURSOR = HICON
HDC = HANDLE
HDDEDATA = HANDLE
HDESK = HANDLE
HDROP = HANDLE
HDWP = HANDLE
HENHMETAFILE = HANDLE
HFILE = Cint
HFONT = HANDLE
HGDIOBJ = HANDLE
HGLOBAL = HANDLE
HHOOK = HANDLE
HICON = HANDLE
HINSTANCE = HANDLE
HKEY = HANDLE
HKL = HANDLE
HLOCAL = HANDLE
HMENU = HANDLE
HMETAFILE = HANDLE
HMODULE = HANDLE
HMONITOR = HANDLE
HPALETTE = HANDLE
HPEN = HANDLE
HRESULT = Clong
HRGN = HANDLE
HRSRC = HANDLE
HSZ = HANDLE
HWINSTA = HANDLE
HWND = HANDLE
INT = Cint
PHANDLE = Ptr{HANDLE}
PVOID = Ptr{Cvoid}
LPVOID = Ptr{Cvoid}
SHORT = Cshort
UCHAR = Cuchar
USHORT = Cushort
VOID = Cvoid
WCHAR = Cwchar_t
WORD = Cushort
PWCHAR = Ptr{WCHAR}
PWORD = Ptr{WORD}
LPWORD = Ptr{WORD}
PDWORD = Ptr{DWORD}
LPDWORD = Ptr{DWORD}
PSTR = Ptr{CHAR} # char*
LPSTR = Ptr{CHAR} # char*
PCSTR = Ptr{CHAR} # char*
LPCSTR = Ptr{CHAR} # char*
PWSTR = Ptr{WCHAR} # wchar_t*
LPWSTR = Ptr{WCHAR} # wchar_t*
PCWSTR = Ptr{WCHAR} # wchar_t*
LPCWSTR = Ptr{WCHAR} # const wchar_t*
Detailed Definitions
Below we include detailed documentation for a few of the aliases defined in this package. We refer to https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types for those not included below.
WinTypes.FALSE
— Constantconst FALSE = Cint(0)
A Boolean variable denoting FALSE.
WinTypes.TRUE
— Constantconst TRUE = Cint(1)
A Boolean variable denoting FALSE. Should only be used in specialized contexts since most functions that reutnr a BOOL
type can return any non-zero value to indicate Boolean truth.
WinTypes.BOOL
— Typeconst BOOL = Cint
A Boolean variable (should be TRUE or FALSE).
This type is declared in WinDef.h
as follows:
typedef int BOOL;
BOOL is a typedef for an integer value that is used in a Boolean context. The header file WinDef.h
also defines two values for use with BOOL.
#define FALSE 0
#define TRUE 1
WinTypes.BOOLEAN
— Typeconst BOOLEAN = BYTE
A Boolean variable (should be TRUE or FALSE).
This type is declared in WinNT.h
as follows:
typedef BYTE BOOLEAN;
WinTypes.BYTE
— Typeconst BYTE = Cuchar
A byte (8 bits).
This type is declared in WinDef.h
as follows:
typedef unsigned char BYTE;
WinTypes.CCHAR
— Typeconst CCHAR = Cchar
An 8-bit Windows (ANSI) character.
This type is declared in WinNT.h
as follows:
typedef char CCHAR;
WinTypes.CHAR
— Typeconst CCHAR = Cchar
An 8-bit Windows (ANSI) character.
This type is declared in WinNT.h
as follows:
typedef char CHAR;
WinTypes.DWORD
— Typeconst DWORD = Culong
A 32-bit unsigned integer.
This type is declared in IntSafe.h
as follows:
typedef unsigned long DWORD;
WinTypes.DWORD32
— Typeconst DWORD32 = UInt32
A 32-bit unsigned integer.
This type is declared in BaseTsd.h
as follows:
typedef unsigned int DWORD32;
WinTypes.DWORD64
— Typeconst DWORD64 = UInt64
A 64-bit unsigned integer.
This type is declared in IntSafe.h
as follows:
typedef unsigned __int64 DWORD64;
WinTypes.DWORDLONG
— Typeconst DWORDLONG = UInt64
A 64-bit unsigned integer.
This type is declared in IntSafe.h
as follows:
typedef unsigned __int64 DWORDLONG;
WinTypes.FLOAT
— Typeconst FLOAT = Cfloat
A floating-point variable.
This type is declared in WinDef.h
as follows:
typedef float FLOAT;
WinTypes.HANDLE
— Typeconst HANDLE = Ptr{Cvoid}
A handle to an object.
This type is declared in WinNT.h
as follows:
typedef PVOID HANDLE;
WinTypes.HKEY
— Typeconst HKEY = HANDLE
A handle to a registry key.
This type is declared in WinDef.h
as follows:
typedef HANDLE HKEY;
WinTypes.PVOID
— Typecosnt PVOID = Ptr{Cvoid}
A pointer to any type.
This type is declared in WinNT.h
as follows:
typedef void *PVOID;
WinTypes.SHORT
— Typeconst SHORT = Cshort
A 16-bit integer.
This type is declared in WinNT.h
as follows:
typedef short SHORT;
WinTypes.UCHAR
— Typeconst UCHAR = Cuchar
An unsigned CHAR.
This type is declared in WinDef.h
as follows:
typedef unsigned char UCHAR
WinTypes.USHORT
— Typeconst USHORT = Cushort
An unsigned SHORT.
This type is declared in WinDef.h
as follows:
typedef unsigned short USHORT;
WinTypes.VOID
— Typeconst VOID = Cvoid
Any type.
This type is declared in WinNT.h
as follows:
#define VOID void
WinTypes.WCHAR
— Typeconst WCHAR = Cwchar_t
A 16-bit Unicode character.
This type is declared in WinNT.h
as follows:
typedef wchar_t WCHAR;
WinTypes.WORD
— Typeconst WORD = Cushort
A 16-bit unsigned integer.
This type is declared in WinDef.h
as follows:
typedef unsigned short WORD;