Windows Kernel32 declarations for synchronization, file and overlapped I/O, processes, threads, fibers, timing, modules, completion ports, and UTF conversion.
Constants
File creation dispositions
| Name | Value | Meaning |
|---|---|---|
CREATE_NEW | 1 | Creates a new file and fails if it already exists. |
CREATE_ALWAYS | 2 | Creates a file or truncates an existing file to zero bytes. |
OPEN_EXISTING | 3 | Opens an existing file. |
OPEN_ALWAYS | 4 | Opens a file or creates it if it does not exist. |
TRUNCATE_EXISTING | 5 | Opens an existing file and truncates it. |
Condition-variable flags
| Name | Value | Meaning |
|---|---|---|
CONDITION_VARIABLE_LOCKMODE_SHARED | 0x1n32 | Requests shared-mode locking for a condition-variable sleep. |
Text conversion
| Name | Value | Meaning |
|---|---|---|
CP_UTF8 | 65001n32 | UTF-8 code-page identifier. |
MB_ERR_INVALID_CHARS | 8n32 | Causes multibyte conversion to fail on invalid input characters. |
Error codes
| Name | Value | Meaning |
|---|---|---|
ERROR_ALREADY_EXISTS | 183n32 | File or directory already exists. |
ERROR_FILE_NOT_FOUND | 2n32 | File not found. |
ERROR_NOT_FOUND | 1168n32 | Element not found. |
ERROR_OPERATION_ABORTED | 995n32 | Operation aborted. |
ERROR_PATH_NOT_FOUND | 3n32 | Path not found. |
ERROR_TIMEOUT | 1460n32 | Operation timed out. |
File-sharing modes
| Name | Value | Meaning |
|---|---|---|
FILE_SHARE_READ | 0x00000001 | Allows subsequent opens to request read access. |
FILE_SHARE_WRITE | 0x00000002 | Allows subsequent opens to request write access. |
FILE_SHARE_DELETE | 0x00000004 | Allows subsequent opens to request delete access. |
Generic access rights
| Name | Value | Meaning |
|---|---|---|
GENERIC_READ | 0x80000000n32 | Requests read access. |
GENERIC_WRITE | 0x40000000n32 | Requests write access. |
GENERIC_EXECUTE | 0x20000000n32 | Requests execute access. |
GENERIC_ALL | 0x10000000n32 | Requests all generic access rights. |
Timeouts
| Name | Value | Meaning |
|---|---|---|
INFINITE | 0xFFFFFFFFn32 | Specifies an infinite timeout. |
Invalid-value sentinels
| Name | Value | Meaning |
|---|---|---|
INVALID_FILE_SIZE | 0xFFFFFFFFn32 | GetFileSize failure sentinel. |
INVALID_SET_FILE_POINTER | 0xFFFFFFFFn32 | SetFilePointer failure sentinel. |
INVALID_FILE_ATTRIBUTES | 0xFFFFFFFFn32 | GetFileAttributes failure sentinel. |
INVALID_HANDLE_VALUE | all bits set (Natx) | Invalid-handle sentinel. |
Wait results
| Name | Value | Meaning |
|---|---|---|
WAIT_OBJECT_0 | 0n32 | Wait succeeded because the object is signaled. |
WAIT_TIMEOUT | 258n32 | Wait timed out. |
WAIT_FAILED | 0xFFFFFFFFn32 | Wait 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.
LPFIBER_START_ROUTINE
(lpFiberParameter --) Defines a fiber-start routine schema with one Natx parameter and no result.LPTHREAD_START_ROUTINE
(lpThreadParameter -- result) Defines a thread-start routine schema with one Natx parameter and a Nat32 result.CONDITION_VARIABLE
(-- CONDITION_VARIABLE) Defines condition-variable storage.Dict schema
CRITICAL_SECTION
(-- CRITICAL_SECTION) Defines critical-section storage.Dict schema
FILETIME
(-- FILETIME) Stores a UTC timestamp as the number of 100-nanosecond intervals since January 1, 1601.Dict schema
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.
LARGE_INTEGER
(-- LARGE_INTEGER) Defines the two-part 64-bit integer value.Dict schema
OVERLAPPED
(-- OVERLAPPED) Defines state for an overlapped operation.Dict schema
| Field | Schema | Role |
|---|---|---|
Internal | Natx | Internal completion status. |
InternalHigh | Natx | Internal transferred-byte value. |
DUMMYUNIONNAME | Nat64 | Byte offset for positioned file I/O; zero for devices without byte offsets. |
hEvent | Natx | Event handle for the operation. |
- The completion mechanism writes
Internaland, 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
| Field | Schema | Role |
|---|---|---|
lpCompletionKey | Natx | Completion key. |
lpOverlapped | OVERLAPPED Ref | I/O operation state address, or an application-defined pointer value from a posted packet. |
Internal | Natx | Reserved. |
dwNumberOfBytesTransferred | Nat32 | Number of bytes transferred. |
PROCESS_INFORMATION
(-- PROCESS_INFORMATION) Defines the handles and identifiers returned for a created process.Dict schema
| Field | Schema | Role |
|---|---|---|
hProcess | Natx | Process handle to close with CloseHandle when no longer needed. |
hThread | Natx | Primary-thread handle to close with CloseHandle when no longer needed. |
dwProcessId | Nat32 | Process identifier. |
dwThreadId | Nat32 | Primary-thread identifier. |
SECURITY_ATTRIBUTES
(-- SECURITY_ATTRIBUTES) Defines security and inheritance attributes for a new object.Dict schema
| Field | Schema | Role |
|---|---|---|
nLength | Nat32 | Size of the structure in bytes; before calling CreateDirectoryW, CreateFileW, CreateProcessW, or CreateThread, set SECURITY_ATTRIBUTES.nLength to this size. |
lpSecurityDescriptor | Natx | Address of the security descriptor. |
bInheritHandle | Int32 | Whether the handle is inheritable. |
SRWLOCK
(-- SRWLOCK) Defines slim reader/writer lock storage.Dict schema
STARTUPINFOW
(-- STARTUPINFOW) Defines startup information for a new process.Dict schema
| Field | Schema | Role |
|---|---|---|
cb | Nat32 | Size of the structure in bytes. |
lpReserved | Natx | Reserved; pass 0nx. |
lpDesktop | Natx | Address of the desktop name, or 0nx. |
lpTitle | Natx | Address of the window title, or 0nx. |
dwX | Nat32 | Initial window x-coordinate. |
dwY | Nat32 | Initial window y-coordinate. |
dwXSize | Nat32 | Initial window width. |
dwYSize | Nat32 | Initial window height. |
dwXCountChars | Nat32 | Console screen-buffer width in characters. |
dwYCountChars | Nat32 | Console screen-buffer height in characters. |
dwFillAttribute | Nat32 | Console screen-buffer fill attributes. |
dwFlags | Nat32 | Flags controlling the startup fields. |
wShowWindow | Nat16 | Initial window show state. |
cbReserved2 | Nat16 | Reserved; pass 0n16. |
lpReserved2 | Natx | Reserved bytes address; pass 0nx. |
hStdInput | Natx | Standard-input handle. |
hStdOutput | Natx | Standard-output handle. |
hStdError | Natx | Standard-error handle. |
SYSTEM_INFO
(-- SYSTEM_INFO) Defines the system-information result record.Dict schema
| Field | Schema | Role |
|---|---|---|
wProcessorArchitecture | Nat16 | Processor architecture. |
wReserved | Nat16 | Reserved field. |
dwPageSize | Nat32 | Page size in bytes. |
lpMinimumApplicationAddress | Natx | Lowest application address. |
lpMaximumApplicationAddress | Natx | Highest application address. |
dwActiveProcessorMask | Natx | Active-processor mask. |
dwNumberOfProcessors | Nat32 | Number of logical processors in the current processor group. |
dwProcessorType | Nat32 | Processor type. |
dwAllocationGranularity | Nat32 | Allocation granularity in bytes. |
wProcessorLevel | Nat16 | Processor level. |
wProcessorRevision | Nat16 | Processor revision. |
Imported functions
Stack effects list a C function's parameters with the first parameter on top; see importFunction.
CancelIoEx
(lpOverlapped hFile -- result) Requests cancellation of pending I/O operations for a file handle.Inputs
lpOverlapped:OVERLAPPEDRefoverlapped operation to cancel, or a typedNILOVERLAPPED Reffor all pending operations on the handle.hFile:Natxfile handle.
Outputs
result:Int32nonzero 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:Natxhandle to close.
Outputs
result:Int32nonzero on success, 0 on failure.
ConvertThreadToFiber
(lpParameter -- result) Converts the calling thread to a fiber.Inputs
lpParameter:Natxparameter passed to the fiber.
Outputs
result:Natxfiber address, or0nxon failure.
CreateDirectoryW
(lpSecurityAttributes lpPathName -- result) Creates a directory.Inputs
lpSecurityAttributes:SECURITY_ATTRIBUTESRefsecurity and inheritance attributes, or a typedNILSECURITY_ATTRIBUTES Reffor none.lpPathName:Natxaddress of a zero-terminated UTF-16 path string.
Outputs
result:Int32nonzero on success, 0 on failure.
CreateFiberEx
(lpParameter lpStartAddress dwFlags dwStackReserveSize dwStackCommitSize -- result) Creates a fiber with separate reserve and commit stack sizes.Inputs
lpParameter:Natxparameter passed to the fiber routine.lpStartAddress:LPFIBER_START_ROUTINEfiber start routine.dwFlags:Nat32fiber-creation flags.dwStackReserveSize:Natxfiber stack reserve size in bytes.dwStackCommitSize:Natxfiber stack commit size in bytes.
Outputs
result:Natxfiber address, or0nxon failure.
CreateFileW
(hTemplateFile dwFlagsAndAttributes dwCreationDisposition lpSecurityAttributes dwShareMode dwDesiredAccess lpFileName -- result) Creates or opens a file or device.Inputs
hTemplateFile:Natxtemplate-file handle, or0nxfor none.dwFlagsAndAttributes:Nat32file attributes and flags.dwCreationDisposition:Nat32action for an existing or missing file; theCREATE_*,OPEN_*, andTRUNCATE_EXISTINGconstants areInt32: cast them, for exampleCREATE_ALWAYS 0n32 cast.lpSecurityAttributes:SECURITY_ATTRIBUTESRefsecurity and inheritance attributes, or a typedNILSECURITY_ATTRIBUTES Reffor none.dwShareMode:Nat32requested sharing mode; cast theInt32FILE_SHARE_*constants.dwDesiredAccess:Nat32requested access rights.lpFileName:Natxaddress of a zero-terminated UTF-16 file name.
Outputs
result:Natxfile or device handle to close withCloseHandlewhen no longer needed, orINVALID_HANDLE_VALUEon failure.
CreateIoCompletionPort
(NumberOfConcurrentThreads CompletionKey ExistingCompletionPort FileHandle -- result) Creates or associates an I/O completion port.Inputs
NumberOfConcurrentThreads:Nat32maximum number of concurrently running threads, or0n32for the default.CompletionKey:Natxcompletion key associated with the file handle.ExistingCompletionPort:Natxexisting completion-port handle, or0nxto create one.FileHandle:Natxfile handle to associate, orINVALID_HANDLE_VALUEto create a port without a file.
Outputs
result:Natxnew or existing completion-port handle, or0nxon failure.
Remarks
- Close a newly created completion-port handle with
CloseHandlewhen 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_INFORMATIONRefcaller-owned storage that receives the process and thread handles and identifiers.lpStartupInfo:STARTUPINFOWRefstartup information.lpCurrentDirectory:Natxaddress of a zero-terminated UTF-16 current-directory string, or0nxfor the calling process's current directory.lpEnvironment:Natxaddress of the environment block, or0nxto inherit the parent's environment.dwCreationFlags:Nat32process-creation flags.bInheritHandles:Int32whether inheritable handles are inherited.lpThreadAttributes:SECURITY_ATTRIBUTESRefthread security and inheritance attributes, or a typedNILSECURITY_ATTRIBUTES Reffor none.lpProcessAttributes:SECURITY_ATTRIBUTESRefprocess security and inheritance attributes, or a typedNILSECURITY_ATTRIBUTES Reffor none.lpCommandLine:Natxaddress of a writable, zero-terminated UTF-16 command-line buffer, or0nxto uselpApplicationName.lpApplicationName:Natxaddress of a zero-terminated UTF-16 executable name, or0nxto take the executable name fromlpCommandLine.
Outputs
result:Int32nonzero on success, 0 on failure.
Remarks
- Close both handles written to
PROCESS_INFORMATIONwithCloseHandlewhen no longer needed.
CreateThread
(lpThreadId dwCreationFlags lpParameter lpStartAddress dwStackSize lpThreadAttributes -- result) Creates a thread.Inputs
lpThreadId:Nat32Refcaller-owned storage that receives the thread identifier, or a typedNILNat32 Reffor none.dwCreationFlags:Nat32thread-creation flags.lpParameter:Natxparameter passed to the thread routine.lpStartAddress:LPTHREAD_START_ROUTINEthread start routine.dwStackSize:Natxinitial stack size in bytes.lpThreadAttributes:SECURITY_ATTRIBUTESRefthread security and inheritance attributes, or a typedNILSECURITY_ATTRIBUTES Reffor none.
Outputs
result:Natxthread handle to close withCloseHandlewhen no longer needed, or0nxon failure.
DeleteFileW
(lpFileName -- result) Deletes a file.Inputs
lpFileName:Natxaddress of a zero-terminated UTF-16 file name.
Outputs
result:Int32nonzero on success, 0 on failure.
EnterCriticalSection
(lpCriticalSection --) Enters a critical section.Inputs
lpCriticalSection:CRITICAL_SECTIONRefcritical section to enter.
Outputs
- None.
FreeLibrary
(hLibModule -- result) Decrements a loaded module's reference count.Inputs
hLibModule:HMODULEmodule handle to release.
Outputs
result:Int32nonzero on success, 0 on failure.
GetExitCodeProcess
(lpExitCode hProcess -- result) Retrieves a process exit code.Inputs
lpExitCode:Nat32Refcaller-owned storage that receives the exit code, or259n32(STILL_ACTIVE) while the process has not terminated.hProcess:Natxprocess handle.
Outputs
result:Int32nonzero on success, 0 on failure.
GetExitCodeThread
(lpExitCode hThread -- result) Retrieves a thread exit code.Inputs
lpExitCode:Nat32Refcaller-owned storage that receives the exit code, or259n32(STILL_ACTIVE) while the thread has not terminated.hThread:Natxthread handle.
Outputs
result:Int32nonzero on success, 0 on failure.
GetFileAttributesW
(lpFileName -- result) Retrieves file-system attributes.Inputs
lpFileName:Natxaddress of a zero-terminated UTF-16 file or directory name.
Outputs
result:Nat32file attributes, orINVALID_FILE_ATTRIBUTESon failure.
GetFileSizeEx
(lpFileSize hFile -- result) Retrieves a file size.Inputs
lpFileSize:LARGE_INTEGERRefcaller-owned storage that receives the file size in bytes.hFile:Natxfile handle.
Outputs
result:Int32nonzero on success, 0 on failure.
GetLastError
(-- result) Retrieves the calling thread's last-error code.Inputs
- None.
Outputs
result:Nat32last-error code for the calling thread.
GetModuleHandleW
(lpModuleName -- result) Retrieves a handle for a loaded module.Inputs
lpModuleName:Natxaddress of a zero-terminated UTF-16 module name, or0nxfor the calling process's executable.
Outputs
result:HMODULEborrowed module handle, or a typedNILvalue 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:Int32whether to wait for the operation to complete.lpNumberOfBytesTransferred:Nat32Refcaller-owned storage that receives the transferred-byte count.lpOverlapped:OVERLAPPEDRefoperation state supplied to the original I/O request, which may still be pending.hFile:Natxfile handle.
Outputs
result:Int32nonzero on success, 0 on failure.
GetProcAddress
(lpProcName hModule -- result) Retrieves a procedure address from a loaded module.Inputs
lpProcName:Natxaddress of a zero-terminated, case-sensitive byte-string export name, or an ordinal in the low 16 bits with all higher bits zero.hModule:HMODULEloaded module handle.
Outputs
result:FARPROCprocedure address, or a typedNILCode on failure.
Remarks
GetProcAddressreturns a genericCodeschema throughFARPROC, not the export's signature. Test@result storageAddress 0nx =before calling; for a different signature, describe it withcodeRef, obtain the address withstorageAddress, and reconstruct it withaddressToReference.
GetQueuedCompletionStatus
(dwMilliseconds lpOverlapped lpCompletionKey lpNumberOfBytesTransferred CompletionPort -- result) Waits for one completion-port packet.Inputs
dwMilliseconds:Nat32wait timeout in milliseconds.lpOverlapped:(OVERLAPPEDRef)Refcaller-owned storage that receives the packet's overlapped pointer value, which may be application-defined for a posted packet.lpCompletionKey:NatxRefcaller-owned storage that receives the completion key.lpNumberOfBytesTransferred:Nat32Refcaller-owned storage that receives the transferred-byte count.CompletionPort:Natxcompletion-port handle.
Outputs
result:Int32nonzero 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-
NILvalue written throughlpOverlappedreports a dequeued failed I/O completion;GetLastErrorsupplies the error. - If a 0 result writes
NILthroughlpOverlapped, 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:Int32whether the wait is alertable.dwMilliseconds:Nat32wait timeout in milliseconds.ulNumEntriesRemoved:Nat32Refcaller-owned storage that receives the number of removed entries.ulCount:Nat32maximum number of entries to remove.lpCompletionPortEntries:OVERLAPPED_ENTRYRefcaller-owned storage for the removed entries.CompletionPort:Natxcompletion-port handle.
Outputs
result:Int32nonzero 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_INFORefcaller-owned storage that receives the system information.
Outputs
- None.
GetTickCount64
(-- result) Retrieves the time since the system started.Inputs
- None.
Outputs
result:Nat32low 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
dwSpinCount:Nat32spin count.lpCriticalSection:CRITICAL_SECTIONRefcritical-section storage to initialize.
Outputs
result:Int32nonzero on success, 0 on failure.
LeaveCriticalSection
(lpCriticalSection --) Leaves a critical section.Inputs
lpCriticalSection:CRITICAL_SECTIONRefcritical section to leave.
Outputs
- None.
LoadLibraryW
(lpLibFileName -- result) Loads a module into the calling process.Inputs
lpLibFileName:Natxaddress of a zero-terminated UTF-16 module file name.
Outputs
result:HMODULEmodule handle to release withFreeLibrarywhen no longer needed, or a typedNILvalue of this schema on failure.
MultiByteToWideChar
(cchWideChar lpWideCharStr cbMultiByte lpMultiByteStr dwFlags CodePage -- result) Converts a multibyte string to UTF-16.Inputs
cchWideChar:Int32output capacity in UTF-16 code units, or 0 to query the required capacity.lpWideCharStr:Natxaddress of output UTF-16 storage, or0nxwhencchWideCharis 0.cbMultiByte:Int32input length in bytes, or -1 for a zero-terminated string.lpMultiByteStr:Natxaddress of the input multibyte string.dwFlags:Nat32conversion flags.CodePage:Nat32code-page identifier such asCP_UTF8.
Outputs
result:Int32number 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:OVERLAPPEDRefopaque pointer copied into the packet without dereferencing. Pass a typedNILOVERLAPPED Reffor no pointer; useaddress OVERLAPPED addressToReferencefor an application address and recover it withlpOverlapped storageAddressafter dequeueing.dwCompletionKey:Natxcompletion key.dwNumberOfBytesTransferred:Nat32transferred-byte count carried by the packet.CompletionPort:Natxcompletion-port handle.
Outputs
result:Int32nonzero on success, 0 on failure.
QueryPerformanceCounter
(lpPerformanceCount -- result) Retrieves the current performance-counter value.Inputs
Outputs
result:Int32nonzero on success, 0 on failure.
QueryPerformanceFrequency
(lpFrequency -- result) Retrieves the performance-counter frequency.Inputs
lpFrequency:Int64Refcaller-owned storage that receives the performance-counter frequency in counts per second.
Outputs
result:Int32nonzero on success, 0 on failure.
ReadFile
(lpOverlapped lpNumberOfBytesRead nNumberOfBytesToRead lpBuffer hFile -- result) Reads data from a file or device.Inputs
lpOverlapped:OVERLAPPEDRefoverlapped-operation state, or a typedNILOVERLAPPED Reffor synchronous I/O.lpNumberOfBytesRead:Nat32Refcaller-owned storage that receives the read byte count for a synchronous handle. This pointer may beNILonly for overlapped I/O.nNumberOfBytesToRead:Nat32maximum number of bytes to read.lpBuffer:Natxaddress of a writable destination buffer that remains valid and unused by the caller until the read completes.hFile:Natxfile or device handle.
Outputs
result:Int32nonzero on successful completion, 0 on failure or while asynchronous I/O is pending.
Remarks
- For a 0 result,
GetLastErrorreturning997n32(ERROR_IO_PENDING) means that I/O remains pending rather than failed. - Retrieve a pending operation's final byte count through
GetOverlappedResultor a completion-port result.
Sleep
(dwMilliseconds --) Suspends the current thread.Inputs
dwMilliseconds:Nat32suspension interval in milliseconds.
Outputs
- None.
SleepConditionVariableSRW
(Flags dwMilliseconds SRWLock ConditionVariable -- result) Atomically releases an SRW lock and waits on a condition variable.Inputs
Flags:Nat32condition-variable flags, includingCONDITION_VARIABLE_LOCKMODE_SHAREDfor shared mode.dwMilliseconds:Nat32wait timeout in milliseconds.SRWLock:SRWLOCKReflock to release while waiting.ConditionVariable:CONDITION_VARIABLERefcondition variable to wait on.
Outputs
result:Int32nonzero on success, 0 on timeout or failure.
Remarks
SleepConditionVariableSRWrequires the caller to holdSRWLockexclusively, or in shared mode whenCONDITION_VARIABLE_LOCKMODE_SHAREDis set.ERROR_TIMEOUTis returned byGetLastErrorwhen the wait times out.
SwitchToFiber
(lpFiber --) Switches execution to a fiber.Inputs
lpFiber:Natxaddress of the fiber to run.
Outputs
- None.
TerminateProcess
(uExitCode hProcess -- result) Terminates a process with an exit code.Inputs
uExitCode:Nat32exit code supplied to the process.hProcess:Natxprocess handle, which the call does not close.
Outputs
result:Int32nonzero on success, 0 on failure.
TryAcquireSRWLockExclusive
(SRWLock -- result) Attempts to acquire an SRW lock exclusively without waiting.Inputs
Outputs
WaitForSingleObject
(dwMilliseconds hHandle -- result) Waits for one object to enter the signaled state.Inputs
dwMilliseconds:Nat32wait timeout in milliseconds.hHandle:Natxobject handle, which the call does not close.
Outputs
result:Nat32WAIT_OBJECT_0when signaled,128n32(WAIT_ABANDONED_0) when an abandoned mutex is acquired,WAIT_TIMEOUTon timeout, orWAIT_FAILEDon failure.
WakeAllConditionVariable
(ConditionVariable --) Wakes all threads waiting on a condition variable.Inputs
ConditionVariable:CONDITION_VARIABLERefcondition variable to wake.
Outputs
- None.
WakeConditionVariable
(ConditionVariable --) Wakes one thread waiting on a condition variable.Inputs
ConditionVariable:CONDITION_VARIABLERefcondition variable to wake.
Outputs
- None.
WideCharToMultiByte
(lpUsedDefaultChar lpDefaultChar cbMultiByte lpMultiByteStr cchWideChar lpWideCharStr dwFlags CodePage -- result) Converts UTF-16 to a multibyte string.Inputs
lpUsedDefaultChar:Natxaddress of anInt32flag that receives nonzero when a default character is used and 0 otherwise, or0nxto ignore it.lpDefaultChar:Natxaddress of the default replacement character, or0nxfor the system default.cbMultiByte:Int32output capacity in bytes, or 0 to query the required capacity.lpMultiByteStr:Natxaddress of output multibyte storage, or0nxwhencbMultiByteis 0.cchWideChar:Int32input length in UTF-16 code units, or -1 for a zero-terminated string.lpWideCharStr:Natxaddress of the input UTF-16 string.dwFlags:Nat32conversion flags.CodePage:Nat32code-page identifier.
Outputs
result:Int32number of bytes written or required, or 0 on failure.
Remarks
- With
CodePageset toCP_UTF8,lpDefaultCharandlpUsedDefaultCharare both0nx.
WriteFile
(lpOverlapped lpNumberOfBytesWritten nNumberOfBytesToWrite lpBuffer hFile -- result) Writes data to a file or device.Inputs
lpOverlapped:OVERLAPPEDRefoverlapped-operation state, or a typedNILOVERLAPPED Reffor synchronous I/O.lpNumberOfBytesWritten:Nat32Refcaller-owned storage that receives the write byte count for a synchronous handle. This pointer may beNILonly for overlapped I/O.nNumberOfBytesToWrite:Nat32number of bytes to write.lpBuffer:Natxaddress of a source buffer that remains valid and unchanged until the write completes.hFile:Natxfile or device handle.
Outputs
result:Int32nonzero on successful completion, 0 on failure or while asynchronous I/O is pending.
Remarks
- For a 0 result,
GetLastErrorreturning997n32(ERROR_IO_PENDING) means that I/O remains pending rather than failed. - Retrieve a pending operation's final byte count through
GetOverlappedResultor 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
- windows/ConditionVariable: SRW-lock-based condition-variable wrapper.
- windows/dispatcher: Windows completion-port dispatcher and callback posting helpers.
- file: File I/O helpers for byte arrays and String values.
- windows/Mutex: SRW lock wrapper with exclusive and shared locking.
- windows/Thread: Windows thread wrapper and helper constructor.
- windows/unicode: UTF-8 to zero-terminated UTF-16 conversion helper.
- windows/ws2_32: Winsock2 declarations for sockets, overlapped I/O, and address-resolution helpers.