Skip to content

Instantly share code, notes, and snippets.

@Varriount
Last active January 3, 2016 19:59
Show Gist options
  • Save Varriount/8512434 to your computer and use it in GitHub Desktop.
Save Varriount/8512434 to your computer and use it in GitHub Desktop.
# This
proc findFirstFileW*(lpFileName: WinString,
lpFindFileData: var TWIN32_FIND_DATA): THandle {.
stdcall, dynlib: "kernel32", winApi.}
# Becomes this when using the Unicode Windows API
proc findFirstFile*(lpFileName: WinString, lpFindFileData: var TWIN32_FIND_DATA): THandle {.
stdcall, dynlib: "kernel32", importc: "FindFirstFileW".}
proc findFirstFileW*(lpFileName: WinString, lpFindFileData: var TWIN32_FIND_DATA): THandle {.
stdcall, dynlib: "kernel32", importc: "FindFirstFileW".}
proc findFirstFile*(lpFileName: string, lpFindFileData: var TWIN32_FIND_DATA): THandle =
return findFirstFile(newWideCString(lpFileName), lpFindFileData)
# And this when using the ANSI api
proc findFirstFile*(lpFileName: WinString, lpFindFileData: var TWIN32_FIND_DATA): THandle {.
stdcall, dynlib: "kernel32", importc: "FindFirstFileA".}
proc findFirstFileA*(lpFileName: WinString, lpFindFileData: var TWIN32_FIND_DATA): THandle {.
stdcall, dynlib: "kernel32", importc: "FindFirstFileA".}
############################
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: winlean [Processing]
proc createProcess*(lpApplicationName, lpCommandLine: WinString;
lpProcessAttributes: ptr TSECURITY_ATTRIBUTES;
lpThreadAttributes: ptr TSECURITY_ATTRIBUTES;
bInheritHandles: WINBOOL; dwCreationFlags: int32;
lpEnvironment, lpCurrentDirectory: WinString;
lpStartupInfo: var TSTARTUPINFO;
lpProcessInformation: var TPROCESS_INFORMATION): WINBOOL {.
stdcall, dynlib: "kernel32", importc: "CreateProcessW".}
proc CreateProcessW*(lpApplicationName, lpCommandLine: WinString;
lpProcessAttributes: ptr TSECURITY_ATTRIBUTES;
lpThreadAttributes: ptr TSECURITY_ATTRIBUTES;
bInheritHandles: WINBOOL; dwCreationFlags: int32;
lpEnvironment, lpCurrentDirectory: WinString;
lpStartupInfo: var TSTARTUPINFO;
lpProcessInformation: var TPROCESS_INFORMATION): WINBOOL {.
stdcall, dynlib: "kernel32", importc: "CreateProcessW".}
proc createProcess*(lpApplicationName, lpCommandLine: string;
lpProcessAttributes: ptr TSECURITY_ATTRIBUTES;
lpThreadAttributes: ptr TSECURITY_ATTRIBUTES;
bInheritHandles: WINBOOL; dwCreationFlags: int32;
lpEnvironment, lpCurrentDirectory: string;
lpStartupInfo: var TSTARTUPINFO;
lpProcessInformation: var TPROCESS_INFORMATION): WINBOOL =
return CreateProcessW(newWideCString(lpApplicationName),
newWideCString(lpCommandLine), lpProcessAttributes,
lpThreadAttributes, bInheritHandles, dwCreationFlags,
newWideCString(lpEnvironment),
newWideCString(lpCurrentDirectory), lpStartupInfo,
lpProcessInformation)
proc formatMessage*(dwFlags: int32; lpSource: pointer;
dwMessageId, dwLanguageId: int32; lpBuffer: pointer;
nSize: int32; Arguments: pointer): int32 {.stdcall,
dynlib: "kernel32", importc: "FormatMessageW".}
proc FormatMessageW*(dwFlags: int32; lpSource: pointer;
dwMessageId, dwLanguageId: int32; lpBuffer: pointer;
nSize: int32; Arguments: pointer): int32 {.stdcall,
dynlib: "kernel32", importc: "FormatMessageW".}
proc getCurrentDirectory*(nBufferLength: int32; lpBuffer: WinString): int32 {.
dynlib: "kernel32", stdcall, importc: "GetCurrentDirectoryW".}
proc GetCurrentDirectoryW*(nBufferLength: int32; lpBuffer: WinString): int32 {.
dynlib: "kernel32", stdcall, importc: "GetCurrentDirectoryW".}
proc getCurrentDirectory*(nBufferLength: int32; lpBuffer: string): int32 =
return GetCurrentDirectoryW(nBufferLength, newWideCString(lpBuffer))
proc setCurrentDirectory*(lpPathName: WinString): int32 {.dynlib: "kernel32",
stdcall, importc: "SetCurrentDirectoryW".}
proc SetCurrentDirectoryW*(lpPathName: WinString): int32 {.dynlib: "kernel32",
stdcall, importc: "SetCurrentDirectoryW".}
proc setCurrentDirectory*(lpPathName: string): int32 =
return SetCurrentDirectoryW(newWideCString(lpPathName))
proc createDirectory*(pathName: WinString; security: pointer = nil): int32 {.
dynlib: "kernel32", stdcall, importc: "CreateDirectoryW".}
proc CreateDirectoryW*(pathName: WinString; security: pointer = nil): int32 {.
dynlib: "kernel32", stdcall, importc: "CreateDirectoryW".}
proc createDirectory*(pathName: string; security: pointer = nil): int32 =
return CreateDirectoryW(newWideCString(pathName), security)
proc removeDirectory*(lpPathName: WinString): int32 {.dynlib: "kernel32",
stdcall, importc: "RemoveDirectoryW".}
proc RemoveDirectoryW*(lpPathName: WinString): int32 {.dynlib: "kernel32",
stdcall, importc: "RemoveDirectoryW".}
proc removeDirectory*(lpPathName: string): int32 =
return RemoveDirectoryW(newWideCString(lpPathName))
proc setEnvironmentVariable*(lpName, lpValue: WinString): int32 {.stdcall,
dynlib: "kernel32", importc: "SetEnvironmentVariableW".}
proc SetEnvironmentVariableW*(lpName, lpValue: WinString): int32 {.stdcall,
dynlib: "kernel32", importc: "SetEnvironmentVariableW".}
proc setEnvironmentVariable*(lpName, lpValue: string): int32 =
return SetEnvironmentVariableW(newWideCString(lpName),
newWideCString(lpValue))
proc getModuleFileName*(handle: THandle; buf: WinString; size: int32): int32 {.
dynlib: "kernel32", stdcall, importc: "GetModuleFileNameW".}
proc GetModuleFileNameW*(handle: THandle; buf: WinString; size: int32): int32 {.
dynlib: "kernel32", stdcall, importc: "GetModuleFileNameW".}
proc getModuleFileName*(handle: THandle; buf: string; size: int32): int32 =
return GetModuleFileNameW(handle, newWideCString(buf), size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment