Windows Kernel32 declarations for synchronization, file and overlapped I/O, processes, threads, fibers, timing, modules, completion ports, and UTF conversion.


Constants

File creation dispositions

NameValueMeaning
CREATE_NEW1Creates a new file and fails if it already exists.
CREATE_ALWAYS2Creates a file or truncates an existing file to zero bytes.
OPEN_EXISTING3Opens an existing file.
OPEN_ALWAYS4Opens a file or creates it if it does not exist.
TRUNCATE_EXISTING5Opens an existing file and truncates it.

Condition-variable flags

NameValueMeaning
CONDITION_VARIABLE_LOCKMODE_SHARED0x1n32Requests shared-mode locking for a condition-variable sleep.

Text conversion

NameValueMeaning
CP_UTF865001n32UTF-8 code-page identifier.
MB_ERR_INVALID_CHARS8n32Causes multibyte conversion to fail on invalid input characters.

Error codes

NameValueMeaning
ERROR_ALREADY_EXISTS183n32File or directory already exists.
ERROR_FILE_NOT_FOUND2n32File not found.
ERROR_NOT_FOUND1168n32Element not found.
ERROR_OPERATION_ABORTED995n32Operation aborted.
ERROR_PATH_NOT_FOUND3n32Path not found.
ERROR_TIMEOUT1460n32Operation timed out.

File-sharing modes

NameValueMeaning
FILE_SHARE_READ0x00000001Allows subsequent opens to request read access.
FILE_SHARE_WRITE0x00000002Allows subsequent opens to request write access.
FILE_SHARE_DELETE0x00000004Allows subsequent opens to request delete access.

Generic access rights

NameValueMeaning
GENERIC_READ0x80000000n32Requests read access.
GENERIC_WRITE0x40000000n32Requests write access.
GENERIC_EXECUTE0x20000000n32Requests execute access.
GENERIC_ALL0x10000000n32Requests all generic access rights.

Timeouts

NameValueMeaning
INFINITE0xFFFFFFFFn32Specifies an infinite timeout.

Invalid-value sentinels

NameValueMeaning
INVALID_FILE_SIZE0xFFFFFFFFn32GetFileSize failure sentinel.
INVALID_SET_FILE_POINTER0xFFFFFFFFn32SetFilePointer failure sentinel.
INVALID_FILE_ATTRIBUTES0xFFFFFFFFn32GetFileAttributes failure sentinel.
INVALID_HANDLE_VALUEall bits set (Natx)Invalid-handle sentinel.

Wait results

NameValueMeaning
WAIT_OBJECT_00n32Wait succeeded because the object is signaled.
WAIT_TIMEOUT258n32Wait timed out.
WAIT_FAILED0xFFFFFFFFn32Wait failed.

Constant example

"control"          use
"windows/kernel32" use

{} () {} [
  CREATE_ALWAYS printStack _:;
  WAIT_TIMEOUT printStack _:;
  CP_UTF8 printStack _:;
  CONDITION_VARIABLE_LOCKMODE_SHARED printStack _:;
] "main" exportFunction

Expected Output During Compilation

2
258n32
65001n32
1n32

Declared schemas

For FARPROC, LPFIBER_START_ROUTINE, and LPTHREAD_START_ROUTINE, each parenthesized effect describes invocation of a non-NIL Code value; evaluating these three names produces NIL Code descriptors.

FARPROC

(-- result) Defines a procedure-address schema with no inputs and an Intx result.

codeRef schema; Intx result

LPFIBER_START_ROUTINE

(lpFiberParameter --) Defines a fiber-start routine schema with one Natx parameter and no result.

codeRef schema; Natx parameter

LPTHREAD_START_ROUTINE

(lpThreadParameter -- result) Defines a thread-start routine schema with one Natx parameter and a Nat32 result.

codeRef schema; Nat32 result

CONDITION_VARIABLE

(-- CONDITION_VARIABLE) Defines condition-variable storage.

Dict schema

FieldSchemaRole
SCHEMA_NAMETextVirtual schema name "CONDITION_VARIABLE".
PtrNatxOpaque storage initialized to 0nx, which is the initialized state; no separate Initialize call or import is needed.

CRITICAL_SECTION

(-- CRITICAL_SECTION) Defines critical-section storage.

Dict schema

FieldSchemaRole
DebugInfoNatxDebug-information address.
LockCountInt32Lock count.
RecursionCountInt32Recursion count.
OwningThreadNatxOwning-thread identifier.
LockSemaphoreNatxLock-semaphore handle.
SpinCountNatxSpin count.

FILETIME

(-- FILETIME) Stores a UTC timestamp as the number of 100-nanosecond intervals since January 1, 1601.

Dict schema

FieldSchemaRole
dwLowDateTimeNat32Low-order 32 bits of the file time.
dwHighDateTimeNat32High-order 32 bits of the file time.

HINSTANCE

(-- HINSTANCE) Defines an instance-handle schema.

Cref schema for a Dict-shaped opaque handle; its public fields are readable schema details but carry no usable handle data and must not be dereferenced or written.

FieldSchemaRole
INSTANCETupleVirtual instance marker; the empty Tuple ().
unusedInt32Unused field.

HMODULE

(-- HMODULE) Defines the module-handle alias.

HINSTANCE alias

LARGE_INTEGER

(-- LARGE_INTEGER) Defines the two-part 64-bit integer value.

Dict schema

FieldSchemaRole
LowPartNat32Low-order 32 bits.
HighPartInt32High-order 32 bits.

OVERLAPPED

(-- OVERLAPPED) Defines state for an overlapped operation.

Dict schema

FieldSchemaRole
InternalNatxInternal completion status.
InternalHighNatxInternal transferred-byte value.
DUMMYUNIONNAMENat64Byte offset for positioned file I/O; zero for devices without byte offsets.
hEventNatxEvent handle for the operation.
  • The completion mechanism writes Internal and, for successful transfers, InternalHigh.
  • Read the final operation status and byte count only after completion is reported through GetOverlappedResult, GetQueuedCompletionStatus, GetQueuedCompletionStatusEx, or an equivalent completion notification.
  • Keep each record alive and do not reuse it until its I/O operation completes, including after cancellation is requested.

OVERLAPPED_ENTRY

(-- OVERLAPPED_ENTRY) Defines one completion-port result entry.

Dict schema

FieldSchemaRole
lpCompletionKeyNatxCompletion key.
lpOverlappedOVERLAPPED RefI/O operation state address, or an application-defined pointer value from a posted packet.
InternalNatxReserved.
dwNumberOfBytesTransferredNat32Number of bytes transferred.

PROCESS_INFORMATION

(-- PROCESS_INFORMATION) Defines the handles and identifiers returned for a created process.

Dict schema

FieldSchemaRole
hProcessNatxProcess handle to close with CloseHandle when no longer needed.
hThreadNatxPrimary-thread handle to close with CloseHandle when no longer needed.
dwProcessIdNat32Process identifier.
dwThreadIdNat32Primary-thread identifier.

SECURITY_ATTRIBUTES

(-- SECURITY_ATTRIBUTES) Defines security and inheritance attributes for a new object.

Dict schema

FieldSchemaRole
nLengthNat32Size of the structure in bytes; before calling CreateDirectoryW, CreateFileW, CreateProcessW, or CreateThread, set SECURITY_ATTRIBUTES.nLength to this size.
lpSecurityDescriptorNatxAddress of the security descriptor.
bInheritHandleInt32Whether the handle is inheritable.

SRWLOCK

(-- SRWLOCK) Defines slim reader/writer lock storage.

Dict schema

FieldSchemaRole
SCHEMA_NAMETextVirtual schema name "SRWLOCK".
PtrNatxOpaque storage initialized to 0nx, which is the initialized state; no separate Initialize call or import is needed.

STARTUPINFOW

(-- STARTUPINFOW) Defines startup information for a new process.

Dict schema

FieldSchemaRole
cbNat32Size of the structure in bytes.
lpReservedNatxReserved; pass 0nx.
lpDesktopNatxAddress of the desktop name, or 0nx.
lpTitleNatxAddress of the window title, or 0nx.
dwXNat32Initial window x-coordinate.
dwYNat32Initial window y-coordinate.
dwXSizeNat32Initial window width.
dwYSizeNat32Initial window height.
dwXCountCharsNat32Console screen-buffer width in characters.
dwYCountCharsNat32Console screen-buffer height in characters.
dwFillAttributeNat32Console screen-buffer fill attributes.
dwFlagsNat32Flags controlling the startup fields.
wShowWindowNat16Initial window show state.
cbReserved2Nat16Reserved; pass 0n16.
lpReserved2NatxReserved bytes address; pass 0nx.
hStdInputNatxStandard-input handle.
hStdOutputNatxStandard-output handle.
hStdErrorNatxStandard-error handle.

SYSTEM_INFO

(-- SYSTEM_INFO) Defines the system-information result record.

Dict schema

FieldSchemaRole
wProcessorArchitectureNat16Processor architecture.
wReservedNat16Reserved field.
dwPageSizeNat32Page size in bytes.
lpMinimumApplicationAddressNatxLowest application address.
lpMaximumApplicationAddressNatxHighest application address.
dwActiveProcessorMaskNatxActive-processor mask.
dwNumberOfProcessorsNat32Number of logical processors in the current processor group.
dwProcessorTypeNat32Processor type.
dwAllocationGranularityNat32Allocation granularity in bytes.
wProcessorLevelNat16Processor level.
wProcessorRevisionNat16Processor revision.

Imported functions

Stack effects list a C function's parameters with the first parameter on top; see importFunction.

AcquireSRWLockExclusive

(SRWLock --) Acquires an SRW lock exclusively.

Inputs

Outputs

  • None.

AcquireSRWLockShared

(SRWLock --) Acquires an SRW lock shared.

Inputs

Outputs

  • None.

CancelIoEx

(lpOverlapped hFile -- result) Requests cancellation of pending I/O operations for a file handle.

Inputs

  • lpOverlapped: OVERLAPPED Ref overlapped operation to cancel, or a typed NIL OVERLAPPED Ref for all pending operations on the handle.
  • hFile: Natx file handle.

Outputs

  • result: Int32 nonzero when cancellation is successfully requested, 0 on failure.

Remarks

  • The call does not wait for canceled I/O to complete.

CloseHandle

(hObject -- result) Closes an open object handle.

Inputs

  • hObject: Natx handle to close.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

ConvertThreadToFiber

(lpParameter -- result) Converts the calling thread to a fiber.

Inputs

  • lpParameter: Natx parameter passed to the fiber.

Outputs

  • result: Natx fiber address, or 0nx on failure.

CreateDirectoryW

(lpSecurityAttributes lpPathName -- result) Creates a directory.

Inputs

  • lpSecurityAttributes: SECURITY_ATTRIBUTES Ref security and inheritance attributes, or a typed NIL SECURITY_ATTRIBUTES Ref for none.
  • lpPathName: Natx address of a zero-terminated UTF-16 path string.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

CreateFiberEx

(lpParameter lpStartAddress dwFlags dwStackReserveSize dwStackCommitSize -- result) Creates a fiber with separate reserve and commit stack sizes.

Inputs

  • lpParameter: Natx parameter passed to the fiber routine.
  • lpStartAddress: LPFIBER_START_ROUTINE fiber start routine.
  • dwFlags: Nat32 fiber-creation flags.
  • dwStackReserveSize: Natx fiber stack reserve size in bytes.
  • dwStackCommitSize: Natx fiber stack commit size in bytes.

Outputs

  • result: Natx fiber address, or 0nx on failure.

CreateFileW

(hTemplateFile dwFlagsAndAttributes dwCreationDisposition lpSecurityAttributes dwShareMode dwDesiredAccess lpFileName -- result) Creates or opens a file or device.

Inputs

  • hTemplateFile: Natx template-file handle, or 0nx for none.
  • dwFlagsAndAttributes: Nat32 file attributes and flags.
  • dwCreationDisposition: Nat32 action for an existing or missing file; the CREATE_*, OPEN_*, and TRUNCATE_EXISTING constants are Int32: cast them, for example CREATE_ALWAYS 0n32 cast.
  • lpSecurityAttributes: SECURITY_ATTRIBUTES Ref security and inheritance attributes, or a typed NIL SECURITY_ATTRIBUTES Ref for none.
  • dwShareMode: Nat32 requested sharing mode; cast the Int32 FILE_SHARE_* constants.
  • dwDesiredAccess: Nat32 requested access rights.
  • lpFileName: Natx address of a zero-terminated UTF-16 file name.

Outputs

CreateIoCompletionPort

(NumberOfConcurrentThreads CompletionKey ExistingCompletionPort FileHandle -- result) Creates or associates an I/O completion port.

Inputs

  • NumberOfConcurrentThreads: Nat32 maximum number of concurrently running threads, or 0n32 for the default.
  • CompletionKey: Natx completion key associated with the file handle.
  • ExistingCompletionPort: Natx existing completion-port handle, or 0nx to create one.
  • FileHandle: Natx file handle to associate, or INVALID_HANDLE_VALUE to create a port without a file.

Outputs

  • result: Natx new or existing completion-port handle, or 0nx on failure.

Remarks

  • Close a newly created completion-port handle with CloseHandle when no longer needed.

CreateProcessW

(lpProcessInformation lpStartupInfo lpCurrentDirectory lpEnvironment dwCreationFlags bInheritHandles lpThreadAttributes lpProcessAttributes lpCommandLine lpApplicationName -- result) Creates a new process and its primary thread.

Inputs

  • lpProcessInformation: PROCESS_INFORMATION Ref caller-owned storage that receives the process and thread handles and identifiers.
  • lpStartupInfo: STARTUPINFOW Ref startup information.
  • lpCurrentDirectory: Natx address of a zero-terminated UTF-16 current-directory string, or 0nx for the calling process's current directory.
  • lpEnvironment: Natx address of the environment block, or 0nx to inherit the parent's environment.
  • dwCreationFlags: Nat32 process-creation flags.
  • bInheritHandles: Int32 whether inheritable handles are inherited.
  • lpThreadAttributes: SECURITY_ATTRIBUTES Ref thread security and inheritance attributes, or a typed NIL SECURITY_ATTRIBUTES Ref for none.
  • lpProcessAttributes: SECURITY_ATTRIBUTES Ref process security and inheritance attributes, or a typed NIL SECURITY_ATTRIBUTES Ref for none.
  • lpCommandLine: Natx address of a writable, zero-terminated UTF-16 command-line buffer, or 0nx to use lpApplicationName.
  • lpApplicationName: Natx address of a zero-terminated UTF-16 executable name, or 0nx to take the executable name from lpCommandLine.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

Remarks

CreateThread

(lpThreadId dwCreationFlags lpParameter lpStartAddress dwStackSize lpThreadAttributes -- result) Creates a thread.

Inputs

  • lpThreadId: Nat32 Ref caller-owned storage that receives the thread identifier, or a typed NIL Nat32 Ref for none.
  • dwCreationFlags: Nat32 thread-creation flags.
  • lpParameter: Natx parameter passed to the thread routine.
  • lpStartAddress: LPTHREAD_START_ROUTINE thread start routine.
  • dwStackSize: Natx initial stack size in bytes.
  • lpThreadAttributes: SECURITY_ATTRIBUTES Ref thread security and inheritance attributes, or a typed NIL SECURITY_ATTRIBUTES Ref for none.

Outputs

  • result: Natx thread handle to close with CloseHandle when no longer needed, or 0nx on failure.

DeleteFileW

(lpFileName -- result) Deletes a file.

Inputs

  • lpFileName: Natx address of a zero-terminated UTF-16 file name.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

EnterCriticalSection

(lpCriticalSection --) Enters a critical section.

Inputs

Outputs

  • None.

FreeLibrary

(hLibModule -- result) Decrements a loaded module's reference count.

Inputs

  • hLibModule: HMODULE module handle to release.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

GetExitCodeProcess

(lpExitCode hProcess -- result) Retrieves a process exit code.

Inputs

  • lpExitCode: Nat32 Ref caller-owned storage that receives the exit code, or 259n32 (STILL_ACTIVE) while the process has not terminated.
  • hProcess: Natx process handle.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

GetExitCodeThread

(lpExitCode hThread -- result) Retrieves a thread exit code.

Inputs

  • lpExitCode: Nat32 Ref caller-owned storage that receives the exit code, or 259n32 (STILL_ACTIVE) while the thread has not terminated.
  • hThread: Natx thread handle.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

GetFileAttributesW

(lpFileName -- result) Retrieves file-system attributes.

Inputs

  • lpFileName: Natx address of a zero-terminated UTF-16 file or directory name.

Outputs

GetFileSizeEx

(lpFileSize hFile -- result) Retrieves a file size.

Inputs

  • lpFileSize: LARGE_INTEGER Ref caller-owned storage that receives the file size in bytes.
  • hFile: Natx file handle.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

GetLastError

(-- result) Retrieves the calling thread's last-error code.

Inputs

  • None.

Outputs

  • result: Nat32 last-error code for the calling thread.

GetModuleHandleW

(lpModuleName -- result) Retrieves a handle for a loaded module.

Inputs

  • lpModuleName: Natx address of a zero-terminated UTF-16 module name, or 0nx for the calling process's executable.

Outputs

  • result: HMODULE borrowed module handle, or a typed NIL value of this schema on failure.

Remarks

  • The call does not increment the module's reference count; do not pass this handle to FreeLibrary.

GetOverlappedResult

(bWait lpNumberOfBytesTransferred lpOverlapped hFile -- result) Retrieves the result of an overlapped operation.

Inputs

  • bWait: Int32 whether to wait for the operation to complete.
  • lpNumberOfBytesTransferred: Nat32 Ref caller-owned storage that receives the transferred-byte count.
  • lpOverlapped: OVERLAPPED Ref operation state supplied to the original I/O request, which may still be pending.
  • hFile: Natx file handle.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

GetProcAddress

(lpProcName hModule -- result) Retrieves a procedure address from a loaded module.

Inputs

  • lpProcName: Natx address of a zero-terminated, case-sensitive byte-string export name, or an ordinal in the low 16 bits with all higher bits zero.
  • hModule: HMODULE loaded module handle.

Outputs

  • result: FARPROC procedure address, or a typed NIL Code on failure.

Remarks

  • GetProcAddress returns a generic Code schema through FARPROC, not the export's signature. Test @result storageAddress 0nx = before calling; for a different signature, describe it with codeRef, obtain the address with storageAddress, and reconstruct it with addressToReference.

GetQueuedCompletionStatus

(dwMilliseconds lpOverlapped lpCompletionKey lpNumberOfBytesTransferred CompletionPort -- result) Waits for one completion-port packet.

Inputs

  • dwMilliseconds: Nat32 wait timeout in milliseconds.
  • lpOverlapped: (OVERLAPPED Ref) Ref caller-owned storage that receives the packet's overlapped pointer value, which may be application-defined for a posted packet.
  • lpCompletionKey: Natx Ref caller-owned storage that receives the completion key.
  • lpNumberOfBytesTransferred: Nat32 Ref caller-owned storage that receives the transferred-byte count.
  • CompletionPort: Natx completion-port handle.

Outputs

  • result: Int32 nonzero for a successful completion packet, 0 for a failed I/O completion or when no packet is dequeued.

Remarks

  • A 0 result with a non-NIL value written through lpOverlapped reports a dequeued failed I/O completion; GetLastError supplies the error.
  • If a 0 result writes NIL through lpOverlapped, no packet is dequeued and the byte-count and completion-key outputs are indeterminate.

GetQueuedCompletionStatusEx

(fAlertable dwMilliseconds ulNumEntriesRemoved ulCount lpCompletionPortEntries CompletionPort -- result) Waits for and removes multiple completion-port packets.

Inputs

  • fAlertable: Int32 whether the wait is alertable.
  • dwMilliseconds: Nat32 wait timeout in milliseconds.
  • ulNumEntriesRemoved: Nat32 Ref caller-owned storage that receives the number of removed entries.
  • ulCount: Nat32 maximum number of entries to remove.
  • lpCompletionPortEntries: OVERLAPPED_ENTRY Ref caller-owned storage for the removed entries.
  • CompletionPort: Natx completion-port handle.

Outputs

  • result: Int32 nonzero when one or more entries are removed, 0 on timeout or failure.

Remarks

  • For I/O completion entries, read the final operation status through lpOverlapped.Internal; a nonzero result only reports that entries were removed.

GetSystemInfo

(lpSystemInfo --) Retrieves system information.

Inputs

  • lpSystemInfo: SYSTEM_INFO Ref caller-owned storage that receives the system information.

Outputs

  • None.

GetTickCount64

(-- result) Retrieves the time since the system started.

Inputs

  • None.

Outputs

  • result: Nat32 low 32 bits of the elapsed milliseconds since the system started.

Known issue: this binding declares GetTickCount64 with a Nat32 result, truncating the Win32 API's 64-bit tick count and wrapping after about 49.7 days. For the full count, obtain the export with GetProcAddress using the loaded HMODULE, then apply storageAddress and addressToReference with a {} Nat64 {convention: stdcall;} codeRef model (stdcall needs "conventions.stdcall" use); do not redeclare the already imported symbol.

InitializeCriticalSectionAndSpinCount

(dwSpinCount lpCriticalSection -- result) Initializes a critical section with a spin count.

Inputs

Outputs

  • result: Int32 nonzero on success, 0 on failure.

LeaveCriticalSection

(lpCriticalSection --) Leaves a critical section.

Inputs

Outputs

  • None.

LoadLibraryW

(lpLibFileName -- result) Loads a module into the calling process.

Inputs

  • lpLibFileName: Natx address of a zero-terminated UTF-16 module file name.

Outputs

  • result: HMODULE module handle to release with FreeLibrary when no longer needed, or a typed NIL value of this schema on failure.

MultiByteToWideChar

(cchWideChar lpWideCharStr cbMultiByte lpMultiByteStr dwFlags CodePage -- result) Converts a multibyte string to UTF-16.

Inputs

  • cchWideChar: Int32 output capacity in UTF-16 code units, or 0 to query the required capacity.
  • lpWideCharStr: Natx address of output UTF-16 storage, or 0nx when cchWideChar is 0.
  • cbMultiByte: Int32 input length in bytes, or -1 for a zero-terminated string.
  • lpMultiByteStr: Natx address of the input multibyte string.
  • dwFlags: Nat32 conversion flags.
  • CodePage: Nat32 code-page identifier such as CP_UTF8.

Outputs

  • result: Int32 number of UTF-16 code units written or required, or 0 on failure.

PostQueuedCompletionStatus

(lpOverlapped dwCompletionKey dwNumberOfBytesTransferred CompletionPort -- result) Posts a completion packet to an I/O completion port.

Inputs

  • lpOverlapped: OVERLAPPED Ref opaque pointer copied into the packet without dereferencing. Pass a typed NIL OVERLAPPED Ref for no pointer; use address OVERLAPPED addressToReference for an application address and recover it with lpOverlapped storageAddress after dequeueing.
  • dwCompletionKey: Natx completion key.
  • dwNumberOfBytesTransferred: Nat32 transferred-byte count carried by the packet.
  • CompletionPort: Natx completion-port handle.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

QueryPerformanceCounter

(lpPerformanceCount -- result) Retrieves the current performance-counter value.

Inputs

  • lpPerformanceCount: Int64 Ref caller-owned storage that receives the performance-counter value.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

QueryPerformanceFrequency

(lpFrequency -- result) Retrieves the performance-counter frequency.

Inputs

  • lpFrequency: Int64 Ref caller-owned storage that receives the performance-counter frequency in counts per second.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

ReadFile

(lpOverlapped lpNumberOfBytesRead nNumberOfBytesToRead lpBuffer hFile -- result) Reads data from a file or device.

Inputs

  • lpOverlapped: OVERLAPPED Ref overlapped-operation state, or a typed NIL OVERLAPPED Ref for synchronous I/O.
  • lpNumberOfBytesRead: Nat32 Ref caller-owned storage that receives the read byte count for a synchronous handle. This pointer may be NIL only for overlapped I/O.
  • nNumberOfBytesToRead: Nat32 maximum number of bytes to read.
  • lpBuffer: Natx address of a writable destination buffer that remains valid and unused by the caller until the read completes.
  • hFile: Natx file or device handle.

Outputs

  • result: Int32 nonzero on successful completion, 0 on failure or while asynchronous I/O is pending.

Remarks

  • For a 0 result, GetLastError returning 997n32 (ERROR_IO_PENDING) means that I/O remains pending rather than failed.
  • Retrieve a pending operation's final byte count through GetOverlappedResult or a completion-port result.

ReleaseSRWLockExclusive

(SRWLock --) Releases an SRW lock held exclusively.

Inputs

Outputs

  • None.

ReleaseSRWLockShared

(SRWLock --) Releases an SRW lock held shared.

Inputs

Outputs

  • None.

Sleep

(dwMilliseconds --) Suspends the current thread.

Inputs

  • dwMilliseconds: Nat32 suspension interval in milliseconds.

Outputs

  • None.

SleepConditionVariableSRW

(Flags dwMilliseconds SRWLock ConditionVariable -- result) Atomically releases an SRW lock and waits on a condition variable.

Inputs

Outputs

  • result: Int32 nonzero on success, 0 on timeout or failure.

Remarks

SwitchToFiber

(lpFiber --) Switches execution to a fiber.

Inputs

  • lpFiber: Natx address of the fiber to run.

Outputs

  • None.

TerminateProcess

(uExitCode hProcess -- result) Terminates a process with an exit code.

Inputs

  • uExitCode: Nat32 exit code supplied to the process.
  • hProcess: Natx process handle, which the call does not close.

Outputs

  • result: Int32 nonzero on success, 0 on failure.

TryAcquireSRWLockExclusive

(SRWLock -- result) Attempts to acquire an SRW lock exclusively without waiting.

Inputs

Outputs

TryAcquireSRWLockShared

(SRWLock -- result) Attempts to acquire an SRW lock shared without waiting.

Inputs

Outputs

WaitForSingleObject

(dwMilliseconds hHandle -- result) Waits for one object to enter the signaled state.

Inputs

  • dwMilliseconds: Nat32 wait timeout in milliseconds.
  • hHandle: Natx object handle, which the call does not close.

Outputs

WakeAllConditionVariable

(ConditionVariable --) Wakes all threads waiting on a condition variable.

Inputs

Outputs

  • None.

WakeConditionVariable

(ConditionVariable --) Wakes one thread waiting on a condition variable.

Inputs

Outputs

  • None.

WideCharToMultiByte

(lpUsedDefaultChar lpDefaultChar cbMultiByte lpMultiByteStr cchWideChar lpWideCharStr dwFlags CodePage -- result) Converts UTF-16 to a multibyte string.

Inputs

  • lpUsedDefaultChar: Natx address of an Int32 flag that receives nonzero when a default character is used and 0 otherwise, or 0nx to ignore it.
  • lpDefaultChar: Natx address of the default replacement character, or 0nx for the system default.
  • cbMultiByte: Int32 output capacity in bytes, or 0 to query the required capacity.
  • lpMultiByteStr: Natx address of output multibyte storage, or 0nx when cbMultiByte is 0.
  • cchWideChar: Int32 input length in UTF-16 code units, or -1 for a zero-terminated string.
  • lpWideCharStr: Natx address of the input UTF-16 string.
  • dwFlags: Nat32 conversion flags.
  • CodePage: Nat32 code-page identifier.

Outputs

  • result: Int32 number of bytes written or required, or 0 on failure.

Remarks

  • With CodePage set to CP_UTF8, lpDefaultChar and lpUsedDefaultChar are both 0nx.

WriteFile

(lpOverlapped lpNumberOfBytesWritten nNumberOfBytesToWrite lpBuffer hFile -- result) Writes data to a file or device.

Inputs

  • lpOverlapped: OVERLAPPED Ref overlapped-operation state, or a typed NIL OVERLAPPED Ref for synchronous I/O.
  • lpNumberOfBytesWritten: Nat32 Ref caller-owned storage that receives the write byte count for a synchronous handle. This pointer may be NIL only for overlapped I/O.
  • nNumberOfBytesToWrite: Nat32 number of bytes to write.
  • lpBuffer: Natx address of a source buffer that remains valid and unchanged until the write completes.
  • hFile: Natx file or device handle.

Outputs

  • result: Int32 nonzero on successful completion, 0 on failure or while asynchronous I/O is pending.

Remarks

  • For a 0 result, GetLastError returning 997n32 (ERROR_IO_PENDING) means that I/O remains pending rather than failed.
  • Retrieve a pending operation's final byte count through GetOverlappedResult or a completion-port result.

Signature example

Printing @QueryPerformanceCounter during compilation shows its imported Code signature.

"control"          use
"windows/kernel32" use

{} Int32 {} [
  @QueryPerformanceCounter printStack _:;
  0
] "main" exportFunction

Expected Output During Compilation

{lpPerformanceCount: Int64 Ref;} Int32 {convention: "";} codeRef

See also