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.TRUEConstant
const 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.

source
WinTypes.BOOLType
const 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

See also: TRUE and FALSE

source
WinTypes.BOOLEANType
const BOOLEAN = BYTE

A Boolean variable (should be TRUE or FALSE).

This type is declared in WinNT.h as follows:

typedef BYTE BOOLEAN;

source
WinTypes.BYTEType
const BYTE = Cuchar

A byte (8 bits).

This type is declared in WinDef.h as follows:

typedef unsigned char BYTE;

source
WinTypes.CCHARType
const CCHAR = Cchar

An 8-bit Windows (ANSI) character.

This type is declared in WinNT.h as follows:

typedef char CCHAR;

source
WinTypes.CHARType
const CCHAR = Cchar

An 8-bit Windows (ANSI) character.

This type is declared in WinNT.h as follows:

typedef char CHAR;

source
WinTypes.DWORDType
const DWORD = Culong

A 32-bit unsigned integer.

This type is declared in IntSafe.h as follows:

typedef unsigned long DWORD;

source
WinTypes.DWORD32Type
const DWORD32 = UInt32

A 32-bit unsigned integer.

This type is declared in BaseTsd.h as follows:

typedef unsigned int DWORD32;

source
WinTypes.DWORD64Type
const DWORD64 = UInt64

A 64-bit unsigned integer.

This type is declared in IntSafe.h as follows:

typedef unsigned __int64 DWORD64;

source
WinTypes.DWORDLONGType
const DWORDLONG = UInt64

A 64-bit unsigned integer.

This type is declared in IntSafe.h as follows:

typedef unsigned __int64 DWORDLONG;

source
WinTypes.FLOATType
const FLOAT = Cfloat

A floating-point variable.

This type is declared in WinDef.h as follows:

typedef float FLOAT;

source
WinTypes.HANDLEType
const HANDLE = Ptr{Cvoid}

A handle to an object.

This type is declared in WinNT.h as follows:

typedef PVOID HANDLE;

source
WinTypes.HKEYType
const HKEY = HANDLE

A handle to a registry key.

This type is declared in WinDef.h as follows:

typedef HANDLE HKEY;

source
WinTypes.PVOIDType
cosnt PVOID = Ptr{Cvoid}

A pointer to any type.

This type is declared in WinNT.h as follows:

typedef void *PVOID;

source
WinTypes.SHORTType
const SHORT = Cshort

A 16-bit integer.

This type is declared in WinNT.h as follows:

typedef short SHORT;

source
WinTypes.UCHARType
const UCHAR = Cuchar

An unsigned CHAR.

This type is declared in WinDef.h as follows:

typedef unsigned char UCHAR

source
WinTypes.USHORTType
const USHORT = Cushort

An unsigned SHORT.

This type is declared in WinDef.h as follows:

typedef unsigned short USHORT;

source
WinTypes.VOIDType
const VOID = Cvoid

Any type.

This type is declared in WinNT.h as follows:

#define VOID void

source
WinTypes.WCHARType
const WCHAR = Cwchar_t

A 16-bit Unicode character.

This type is declared in WinNT.h as follows:

typedef wchar_t WCHAR;

source
WinTypes.WORDType
const WORD = Cushort

A 16-bit unsigned integer.

This type is declared in WinDef.h as follows:

typedef unsigned short WORD;

source