This module implements a small wrapper for some needed Win API procedures, so that the Nim compiler does not depend on the huge Windows module.
AddrInfo = object ai_flags*: cint ## Input flags. ai_family*: cint ## Address family of socket. ai_socktype*: cint ## Socket type. ai_protocol*: cint ## Protocol of socket. ai_addrlen*: csize_t ## Length of socket address. ai_canonname*: cstring ## Canonical name of service location. ai_addr*: ptr SockAddr ## Socket address of socket. ai_next*: ptr AddrInfo ## Pointer to next in list.
BY_HANDLE_FILE_INFORMATION = object dwFileAttributes*: DWORD ftCreationTime*: FILETIME ftLastAccessTime*: FILETIME ftLastWriteTime*: FILETIME dwVolumeSerialNumber*: DWORD nFileSizeHigh*: DWORD nFileSizeLow*: DWORD nNumberOfLinks*: DWORD nFileIndexHigh*: DWORD nFileIndexLow*: DWORD
FILETIME = object dwLowDateTime*: DWORD dwHighDateTime*: DWORD
Hostent = object h_name*: cstring h_aliases*: cstringArray h_addrtype*: int16 h_length*: int16 h_addr_list*: cstringArray
In6_addr {.importc: "IN6_ADDR", header: "winsock2.h".} = object
bytes* {.importc: "u.Byte".}: array[0 .. 15, char]KEY_EVENT_RECORD = object eventType*: int16 bKeyDown*: WINBOOL wRepeatCount*: int16 wVirtualKeyCode*: int16 wVirtualScanCode*: int16 uChar*: int16 dwControlKeyState*: DWORD
OSVERSIONINFO = object dwOSVersionInfoSize*: DWORD dwMajorVersion*: DWORD dwMinorVersion*: DWORD dwBuildNumber*: DWORD dwPlatformId*: DWORD szCSDVersion*: array[0 .. 127, WinChar]
OVERLAPPED {.pure, inheritable.} = object
internal*: PULONG
internalHigh*: PULONG
offset*: DWORD
offsetHigh*: DWORD
hEvent*: HandlePOVERLAPPED_COMPLETION_ROUTINE = proc (para1: DWORD; para2: DWORD;
para3: POVERLAPPED) {.stdcall.}PROCESS_INFORMATION = object hProcess*: Handle hThread*: Handle dwProcessId*: int32 dwThreadId*: int32
SECURITY_ATTRIBUTES = object nLength*: int32 lpSecurityDescriptor*: pointer bInheritHandle*: WINBOOL
Servent = object
s_name*: cstring
s_aliases*: cstringArray
when defined(cpu64):
s_proto*: cstring
s_port*: int16
else:
s_port*: int16
s_proto*: cstringSID_IDENTIFIER_AUTHORITY {.importc, header: "<windows.h>".} = object
value* {.importc: "Value".}: array[6, BYTE]SockAddr {.importc: "SOCKADDR", header: "winsock2.h".} = object
sa_family*: uint16
sa_data*: array[0 .. 13, char]Sockaddr_in {.importc: "SOCKADDR_IN", header: "winsock2.h".} = object
sin_family*: uint16
sin_port*: uint16
sin_addr*: InAddr
sin_zero*: array[0 .. 7, char]Sockaddr_in6 {.importc: "SOCKADDR_IN6", header: "ws2tcpip.h".} = object
sin6_family*: uint16
sin6_port*: uint16
sin6_flowinfo*: int32
sin6_addr*: In6_addr
sin6_scope_id*: int32Sockaddr_storage {.importc: "SOCKADDR_STORAGE", header: "winsock2.h".} = object
ss_family*: uint16STARTUPINFO = object cb*: int32 lpReserved*: cstring lpDesktop*: cstring lpTitle*: cstring dwX*: int32 dwY*: int32 dwXSize*: int32 dwYSize*: int32 dwXCountChars*: int32 dwYCountChars*: int32 dwFillAttribute*: int32 dwFlags*: int32 wShowWindow*: int16 cbReserved2*: int16 lpReserved2*: pointer hStdInput*: Handle hStdOutput*: Handle hStdError*: Handle
WIN32_FIND_DATA {.pure.} = object
dwFileAttributes*: int32
ftCreationTime*: FILETIME
ftLastAccessTime*: FILETIME
ftLastWriteTime*: FILETIME
nFileSizeHigh*: int32
nFileSizeLow*: int32
cFileName*: array[0 .. 260 - 1, WinChar]
cAlternateFileName*: array[0 .. 13, WinChar]WSAPROC_ACCEPTEX = proc (sListenSocket: SocketHandle;
sAcceptSocket: SocketHandle; lpOutputBuffer: pointer;
dwReceiveDataLength: DWORD;
dwLocalAddressLength: DWORD;
dwRemoteAddressLength: DWORD;
lpdwBytesReceived: ptr DWORD; lpOverlapped: POVERLAPPED): bool {.
stdcall, ...gcsafe, raises: [].}WSAPROC_CONNECTEX = proc (s: SocketHandle; name: ptr SockAddr; namelen: cint;
lpSendBuffer: pointer; dwSendDataLength: DWORD;
lpdwBytesSent: ptr DWORD; lpOverlapped: POVERLAPPED): bool {.
stdcall, ...gcsafe, raises: [].}WSAPROC_GETACCEPTEXSOCKADDRS = proc (lpOutputBuffer: pointer;
dwReceiveDataLength: DWORD;
dwLocalAddressLength: DWORD;
dwRemoteAddressLength: DWORD;
LocalSockaddr: ptr PSockAddr;
LocalSockaddrLength: ptr cint;
RemoteSockaddr: ptr PSockAddr;
RemoteSockaddrLength: ptr cint) {.stdcall,
...gcsafe, raises: [].}WSAID_ACCEPTEX: GUID = GUID(D1: 0xB5367DF1'i32, D2: 0xCBAC'i16, D3: 0x000011CF, D4: [
0x95'i8, 0xCA'i8, 0x00'i8, 0x80'i8, 0x5F'i8, 0x48'i8, 0xA1'i8, 0x92'i8])ERROR_FILE_NOT_FOUND = 2
proc allocateAndInitializeSid(pIdentifierAuthority: ptr SID_IDENTIFIER_AUTHORITY;
nSubAuthorityCount: BYTE; nSubAuthority0: DWORD;
nSubAuthority1: DWORD; nSubAuthority2: DWORD;
nSubAuthority3: DWORD; nSubAuthority4: DWORD;
nSubAuthority5: DWORD; nSubAuthority6: DWORD;
nSubAuthority7: DWORD; pSid: ptr PSID): WINBOOL {.
stdcall, dynlib: "Advapi32", importc: "AllocateAndInitializeSid",
...raises: [], tags: [], forbids: [].}proc createNamedPipe(lpName: WideCString; dwOpenMode, dwPipeMode, nMaxInstances,
nOutBufferSize, nInBufferSize, nDefaultTimeOut: int32;
lpSecurityAttributes: ptr SECURITY_ATTRIBUTES): Handle {.
stdcall, dynlib: "kernel32", importc: "CreateNamedPipeW", sideEffect,
...raises: [], tags: [], forbids: [].}proc createProcessW(lpApplicationName, lpCommandLine: WideCString;
lpProcessAttributes: ptr SECURITY_ATTRIBUTES;
lpThreadAttributes: ptr SECURITY_ATTRIBUTES;
bInheritHandles: WINBOOL; dwCreationFlags: int32;
lpEnvironment, lpCurrentDirectory: WideCString;
lpStartupInfo: var STARTUPINFO;
lpProcessInformation: var PROCESS_INFORMATION): WINBOOL {.
stdcall, dynlib: "kernel32", importc: "CreateProcessW", sideEffect,
...raises: [], tags: [], forbids: [].}proc duplicateHandle(hSourceProcessHandle: Handle; hSourceHandle: Handle;
hTargetProcessHandle: Handle; lpTargetHandle: ptr Handle;
dwDesiredAccess: DWORD; bInheritHandle: WINBOOL;
dwOptions: DWORD): WINBOOL {.stdcall, dynlib: "kernel32",
importc: "DuplicateHandle", ...raises: [], tags: [], forbids: [].}proc getQueuedCompletionStatus(CompletionPort: Handle;
lpNumberOfBytesTransferred: PDWORD;
lpCompletionKey: PULONG_PTR;
lpOverlapped: ptr POVERLAPPED;
dwMilliseconds: DWORD): WINBOOL {.stdcall,
dynlib: "kernel32", importc: "GetQueuedCompletionStatus", ...raises: [],
tags: [], forbids: [].}proc peekNamedPipe(hNamedPipe: Handle; lpBuffer: pointer = nil;
nBufferSize: int32 = 0; lpBytesRead: ptr int32 = nil;
lpTotalBytesAvail: ptr int32 = nil;
lpBytesLeftThisMessage: ptr int32 = nil): bool {.stdcall,
dynlib: "kernel32", importc: "PeekNamedPipe", ...raises: [], tags: [],
forbids: [].}proc WSAIoctl(s: SocketHandle; dwIoControlCode: DWORD; lpvInBuffer: pointer;
cbInBuffer: DWORD; lpvOutBuffer: pointer; cbOutBuffer: DWORD;
lpcbBytesReturned: PDWORD; lpOverlapped: POVERLAPPED;
lpCompletionRoutine: POVERLAPPED_COMPLETION_ROUTINE): cint {.
stdcall, importc: "WSAIoctl", dynlib: "Ws2_32.dll", ...raises: [], tags: [],
forbids: [].}proc WSARecvFrom(s: SocketHandle; buf: ptr TWSABuf; bufCount: DWORD;
bytesReceived: PDWORD; flags: PDWORD; name: ptr SockAddr;
namelen: ptr cint; lpOverlapped: POVERLAPPED;
completionProc: POVERLAPPED_COMPLETION_ROUTINE): cint {.
stdcall, importc: "WSARecvFrom", dynlib: "Ws2_32.dll", ...raises: [], tags: [],
forbids: [].}proc WSASendTo(s: SocketHandle; buf: ptr TWSABuf; bufCount: DWORD;
bytesSent: PDWORD; flags: DWORD; name: ptr SockAddr;
namelen: cint; lpOverlapped: POVERLAPPED;
completionProc: POVERLAPPED_COMPLETION_ROUTINE): cint {.stdcall,
importc: "WSASendTo", dynlib: "Ws2_32.dll", ...raises: [], tags: [],
forbids: [].}
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/winlean.html