Skip to main content

Integer Types

Unlike Dart, which has a single integer type for storing values between -263-1 and 263, the Win32 API utilizes various integer types in both signed and unsigned forms.

The following table lists the common integer types encountered when working with Win32 APIs:

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

When calling a function and passing a value, you don't need to worry about converting from a Dart int type to the appropriate native representation: win32 includes all the metadata to handle this conversion for you.

NOTE

However, understanding the type of data becomes crucial when a function returns a value. In Win32, functions often use a Pointer argument that they fill with the relevant data, making it important to know the expected data type.

win32 provides typedefs for all common Win32 integer types, so you don't need to remember the size and sign of types like DWORD.

Here’s an example demonstrating how to retrieve the size of system memory using win32:

memory.dart
import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';

void main() {
final lpMemorySize = calloc<ULONGLONG>();
GetPhysicallyInstalledSystemMemory(lpMemorySize);
final memorySizeMB = lpMemorySize.value ~/ 1024;
print('System has ${memorySizeMB}MB of RAM installed.');
free(lpMemorySize);
}
Good to know:

lpMemorySize could also be allocated as calloc<ULONG64>() or calloc<Uint64>() — they all refer to the same type.

For a more detailed demonstration of retrieving system information, see the sysinfo.dart example.