Skip to main content

Integer Types

Dart has a single, arbitrary-precision int type. In contrast, the Win32 API uses many fixed-width integer types with explicit size and signedness.

When calling Win32 functions, package:win32 handles marshaling Dart int values into the correct native representation for you. However, when receiving values through pointers or struct fields, you must allocate the correct native type or risk silent data corruption.

Understanding these native integer types is therefore essential when working with output parameters, buffers, and structs.

Common Win32 Integer Types​

The following table lists the most common integer types encountered in the Win32 API and their dart:ffi equivalents:

Common Win32 Namesdart:ffi TypeSizeSignedRange
BYTE, UINT8, CHARUint88 bitsNo0 to 255
INT8Int88 bitsYes-128 to 127
WORD, ATOM, UINT16, USHORTUint1616 bitsNo0 to 65535
INT16, SHORTInt1616 bitsYes-32768 to 32767
DWORD, UINT, UINT32, ULONGUint3232 bitsNo0 to 232-1
INT, INT32, LONGInt3232 bitsYes-231 to 231-1
DWORDLONG, ULONGLONG, UINT64, ULONG64Uint6464 bitsNo0 to 264-1
LONGLONG, INT64Int6464 bitsYes-263 to 263-1
LONG_PTRIntPtr32/64 bitsYesMatches pointer length
UINT_PTR, ULONG_PTRIntPtr32/64 bitsNoMatches pointer length
HANDLEPointer32/64 bitsNoOpaque handle (not numeric data)

Typedefs in package:win32​

package:win32 provides Dart typedefs for all common Win32 integer types, such as DWORD, ULONG64, and ULONGLONG.

You should prefer these typedefs over raw dart:ffi types when interacting with Win32 APIs, as they match the native signatures exactly and improve readability.

Output Parameters and Pointers​

Many Win32 functions return values through output parameters such as LPDWORD, PULONG64, or LPINT.

The FFI type you allocate determines how the native bytes are interpreted in Dart. Using the wrong type will produce incorrect values.

For example, the GetPhysicallyInstalledSystemMemory function fills a PULONGLONG output parameter:

sysinfo.dart
String getSystemMemorySize() {
return using((arena) {
// ULONGLONG matches the native PULONGLONG output parameter.
final lpMemorySize = arena<ULONGLONG>();
final Win32Result(:value, :error) = GetPhysicallyInstalledSystemMemory(
lpMemorySize,
);
if (!value) throw WindowsException(error.toHRESULT());
return lpMemorySize.value ~/ 1024;
});
}