merge from upstream and convert to ^File types

This commit is contained in:
jason
2022-05-16 13:49:57 -04:00
276 changed files with 30251 additions and 7935 deletions
+6
View File
@@ -3,6 +3,8 @@ package sys_windows
foreign import advapi32 "system:Advapi32.lib"
HCRYPTPROV :: distinct HANDLE
@(default_calling_convention="stdcall")
foreign advapi32 {
@(link_name = "SystemFunction036")
@@ -10,6 +12,10 @@ foreign advapi32 {
OpenProcessToken :: proc(ProcessHandle: HANDLE,
DesiredAccess: DWORD,
TokenHandle: ^HANDLE) -> BOOL ---
CryptAcquireContextW :: proc(hProv: ^HCRYPTPROV, szContainer, szProvider: wstring, dwProvType, dwFlags: DWORD) -> DWORD ---
CryptGenRandom :: proc(hProv: HCRYPTPROV, dwLen: DWORD, buf: LPVOID) -> DWORD ---
CryptReleaseContext :: proc(hProv: HCRYPTPROV, dwFlags: DWORD) -> DWORD ---
}
// Necessary to create a token to impersonate a user with for CreateProcessAsUser
+1 -1
View File
@@ -7,5 +7,5 @@ BCRYPT_USE_SYSTEM_PREFERRED_RNG: DWORD : 0x00000002
@(default_calling_convention="stdcall")
foreign bcrypt {
BCryptGenRandom :: proc(hAlgorithm: LPVOID, pBuffer: ^u8, cbBuffer: ULONG, dwFlags: ULONG) -> LONG ---
BCryptGenRandom :: proc(hAlgorithm: LPVOID, pBuffer: [^]u8, cbBuffer: ULONG, dwFlags: ULONG) -> LONG ---
}
+11 -38
View File
@@ -51,54 +51,27 @@ BLUETOOTH_DEVICE_INFO :: struct {
name: [BLUETOOTH_MAX_NAME_SIZE]u16, // Name of the device
}
@(default_calling_convention = "std")
@(default_calling_convention="stdcall")
foreign bthprops {
/*
Version
*/
@(link_name="BluetoothIsVersionAvailable") bluetooth_is_version_available :: proc(
major: u8, minor: u8,
) -> BOOL ---
BluetoothIsVersionAvailable :: proc(major: u8, minor: u8) -> BOOL ---
/*
Radio enumeration
*/
@(link_name="BluetoothFindFirstRadio") bluetooth_find_first_radio :: proc(
find_radio_params: ^BLUETOOTH_FIND_RADIO_PARAMS, radio: ^HANDLE,
) -> HBLUETOOTH_RADIO_FIND ---
@(link_name="BluetoothFindNextRadio") bluetooth_find_next_radio :: proc(
handle: HBLUETOOTH_RADIO_FIND, radio: ^HANDLE,
) -> BOOL ---
@(link_name="BluetoothFindRadioClose") bluetooth_find_radio_close :: proc(
handle: HBLUETOOTH_RADIO_FIND,
) -> BOOL ---
@(link_name="BluetoothGetRadioInfo") bluetooth_get_radio_info :: proc(
radio: HANDLE, radio_info: ^BLUETOOTH_RADIO_INFO,
) -> DWORD ---
BluetoothFindFirstRadio :: proc(find_radio_params: ^BLUETOOTH_FIND_RADIO_PARAMS, radio: ^HANDLE) -> HBLUETOOTH_RADIO_FIND ---
BluetoothFindNextRadio :: proc(handle: HBLUETOOTH_RADIO_FIND, radio: ^HANDLE) -> BOOL ---
BluetoothFindRadioClose :: proc(handle: HBLUETOOTH_RADIO_FIND) -> BOOL ---
BluetoothGetRadioInfo :: proc(radio: HANDLE, radio_info: ^BLUETOOTH_RADIO_INFO) -> DWORD ---
/*
Device enumeration
*/
@(link_name="BluetoothFindFirstDevice") bluetooth_find_first_device :: proc(
search_params: ^BLUETOOTH_DEVICE_SEARCH_PARAMS, device_info: ^BLUETOOTH_DEVICE_INFO,
) -> HBLUETOOTH_DEVICE_FIND ---
@(link_name="BluetoothFindNextDevice") bluetooth_find_next_device :: proc(
handle: HBLUETOOTH_DEVICE_FIND, device_info: ^BLUETOOTH_DEVICE_INFO,
) -> BOOL ---
@(link_name="BluetoothFindDeviceClose") bluetooth_find_device_close :: proc(
handle: HBLUETOOTH_DEVICE_FIND,
) -> BOOL ---
@(link_name="BluetoothGetDeviceInfo") bluetooth_get_device_info :: proc(
radio: HANDLE, device_info: ^BLUETOOTH_DEVICE_INFO,
) -> DWORD ---
@(link_name="BluetoothDisplayDeviceProperties") bluetooth_display_device_properties :: proc(
hwnd_parent: HWND, device_info: ^BLUETOOTH_DEVICE_INFO,
) -> BOOL ---
BluetoothFindFirstDevice :: proc(search_params: ^BLUETOOTH_DEVICE_SEARCH_PARAMS, device_info: ^BLUETOOTH_DEVICE_INFO) -> HBLUETOOTH_DEVICE_FIND ---
BluetoothFindNextDevice :: proc(handle: HBLUETOOTH_DEVICE_FIND, device_info: ^BLUETOOTH_DEVICE_INFO) -> BOOL ---
BluetoothFindDeviceClose :: proc(handle: HBLUETOOTH_DEVICE_FIND) -> BOOL ---
BluetoothGetDeviceInfo :: proc(radio: HANDLE, device_info: ^BLUETOOTH_DEVICE_INFO) -> DWORD ---
BluetoothDisplayDeviceProperties :: proc(hwnd_parent: HWND, device_info: ^BLUETOOTH_DEVICE_INFO) -> BOOL ---
}
+168
View File
@@ -0,0 +1,168 @@
// +build windows
package sys_windows
foreign import "system:Comdlg32.lib"
import "core:strings"
LPOFNHOOKPROC :: #type proc "stdcall" (hdlg: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> UINT_PTR
OPENFILENAMEW :: struct {
lStructSize: DWORD,
hwndOwner: HWND,
hInstance: HINSTANCE,
lpstrFilter: wstring,
lpstrCustomFilter: wstring,
nMaxCustFilter: DWORD,
nFilterIndex: DWORD,
lpstrFile: wstring,
nMaxFile: DWORD,
lpstrFileTitle: wstring,
nMaxFileTitle: DWORD,
lpstrInitialDir: wstring,
lpstrTitle: wstring,
Flags: DWORD,
nFileOffset: WORD,
nFileExtension: WORD,
lpstrDefExt: wstring,
lCustData: LPARAM,
lpfnHook: LPOFNHOOKPROC,
lpTemplateName: wstring,
lpEditInfo: rawptr, // LPEDITMENU,
lpstrPrompt: wstring,
pvReserved: rawptr,
dwReserved: DWORD,
FlagsEx: DWORD,
}
@(default_calling_convention="stdcall")
foreign Comdlg32 {
GetOpenFileNameW :: proc(arg1: ^OPENFILENAMEW) -> BOOL ---
GetSaveFileNameW :: proc(arg1: ^OPENFILENAMEW) -> BOOL ---
CommDlgExtendedError :: proc() -> u32 ---
}
OPEN_TITLE :: "Select file to open"
OPEN_FLAGS :: u32(OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST)
OPEN_FLAGS_MULTI :: OPEN_FLAGS | OFN_ALLOWMULTISELECT | OFN_EXPLORER
SAVE_TITLE :: "Select file to save"
SAVE_FLAGS :: u32(OFN_OVERWRITEPROMPT | OFN_EXPLORER)
SAVE_EXT :: "txt"
Open_Save_Mode :: enum {
Open = 0,
Save = 1,
}
_open_file_dialog :: proc(title: string, dir: string,
filters: []string, default_filter: u32,
flags: u32, default_ext: string,
mode: Open_Save_Mode, allocator := context.temp_allocator) -> (path: string, ok: bool = true) {
context.allocator = allocator
file_buf := make([]u16, MAX_PATH_WIDE)
defer if !ok {
delete(file_buf)
}
// Filters need to be passed as a pair of strings (title, filter)
filter_len := u32(len(filters))
if filter_len % 2 != 0 {
return "", false
}
filter: string
filter = strings.join(filters, "\u0000", context.temp_allocator)
filter = strings.concatenate({filter, "\u0000"}, context.temp_allocator)
ofn := OPENFILENAMEW{
lStructSize = size_of(OPENFILENAMEW),
lpstrFile = wstring(&file_buf[0]),
nMaxFile = MAX_PATH_WIDE,
lpstrTitle = utf8_to_wstring(title, context.temp_allocator),
lpstrFilter = utf8_to_wstring(filter, context.temp_allocator),
lpstrInitialDir = utf8_to_wstring(dir, context.temp_allocator),
nFilterIndex = u32(clamp(default_filter, 1, filter_len / 2)),
lpstrDefExt = utf8_to_wstring(default_ext, context.temp_allocator),
Flags = u32(flags),
}
switch mode {
case .Open:
ok = bool(GetOpenFileNameW(&ofn))
case .Save:
ok = bool(GetSaveFileNameW(&ofn))
case:
ok = false
}
if !ok {
return
}
file_name, _ := utf16_to_utf8(file_buf[:], allocator)
path = strings.trim_right_null(file_name)
return
}
select_file_to_open :: proc(title := OPEN_TITLE, dir := ".",
filters := []string{"All Files", "*.*"}, default_filter := u32(1),
flags := OPEN_FLAGS, allocator := context.temp_allocator) -> (path: string, ok: bool) {
path, ok = _open_file_dialog(title, dir, filters, default_filter, flags, "", Open_Save_Mode.Open, allocator)
return
}
select_file_to_save :: proc(title := SAVE_TITLE, dir := ".",
filters := []string{"All Files", "*.*"}, default_filter := u32(1),
flags := SAVE_FLAGS, default_ext := SAVE_EXT,
allocator := context.temp_allocator) -> (path: string, ok: bool) {
path, ok = _open_file_dialog(title, dir, filters, default_filter, flags, default_ext, Open_Save_Mode.Save, allocator)
return
}
// TODO: Implement convenience function for select_file_to_open with ALLOW_MULTI_SELECT that takes
// it output of the form "path\u0000\file1u\0000file2" and turns it into []string with the path + file pre-concatenated for you.
OFN_ALLOWMULTISELECT :: 0x00000200 // NOTE(Jeroen): Without OFN_EXPLORER it uses the Win3 dialog.
OFN_CREATEPROMPT :: 0x00002000
OFN_DONTADDTORECENT :: 0x02000000
OFN_ENABLEHOOK :: 0x00000020
OFN_ENABLEINCLUDENOTIFY :: 0x00400000
OFN_ENABLESIZING :: 0x00800000
OFN_ENABLETEMPLATE :: 0x00000040
OFN_ENABLETEMPLATEHANDLE :: 0x00000080
OFN_EXPLORER :: 0x00080000
OFN_EXTENSIONDIFFERENT :: 0x00000400
OFN_FILEMUSTEXIST :: 0x00001000
OFN_FORCESHOWHIDDEN :: 0x10000000
OFN_HIDEREADONLY :: 0x00000004
OFN_LONGNAMES :: 0x00200000
OFN_NOCHANGEDIR :: 0x00000008
OFN_NODEREFERENCELINKS :: 0x00100000
OFN_NOLONGNAMES :: 0x00040000
OFN_NONETWORKBUTTON :: 0x00020000
OFN_NOREADONLYRETURN :: 0x00008000
OFN_NOTESTFILECREATE :: 0x00010000
OFN_NOVALIDATE :: 0x00000100
OFN_OVERWRITEPROMPT :: 0x00000002
OFN_PATHMUSTEXIST :: 0x00000800
OFN_READONLY :: 0x00000001
OFN_SHAREAWARE :: 0x00004000
OFN_SHOWHELP :: 0x00000010
CDERR_DIALOGFAILURE :: 0x0000FFFF
CDERR_GENERALCODES :: 0x00000000
CDERR_STRUCTSIZE :: 0x00000001
CDERR_INITIALIZATION :: 0x00000002
CDERR_NOTEMPLATE :: 0x00000003
CDERR_NOHINSTANCE :: 0x00000004
CDERR_LOADSTRFAILURE :: 0x00000005
CDERR_FINDRESFAILURE :: 0x00000006
CDERR_LOADRESFAILURE :: 0x00000007
CDERR_LOCKRESFAILURE :: 0x00000008
CDERR_MEMALLOCFAILURE :: 0x00000009
CDERR_MEMLOCKFAILURE :: 0x0000000A
CDERR_NOHOOK :: 0x0000000B
CDERR_REGISTERMSGFAIL :: 0x0000000C
+6
View File
@@ -62,5 +62,11 @@ foreign gdi32 {
ChoosePixelFormat :: proc(hdc: HDC, ppfd: ^PIXELFORMATDESCRIPTOR) -> c_int ---
SwapBuffers :: proc(HDC) -> BOOL ---
SetDCBrushColor :: proc(hdc: HDC, color: COLORREF) -> COLORREF ---
GetDCBrushColor :: proc(hdc: HDC) -> COLORREF ---
PatBlt :: proc(hdc: HDC, x, y, w, h: c_int, rop: DWORD) -> BOOL ---
}
RGB :: #force_inline proc "contextless" (r, g, b: u8) -> COLORREF {
return transmute(COLORREF)[4]u8{r, g, b, 0}
}
+62 -4
View File
@@ -3,11 +3,10 @@ package sys_windows
foreign import kernel32 "system:Kernel32.lib"
@(default_calling_convention="stdcall")
foreign kernel32 {
OutputDebugStringA :: proc(lpOutputString: LPCSTR) ---
OutputDebugStringA :: proc(lpOutputString: LPCSTR) --- // The only A thing that is allowed
OutputDebugStringW :: proc(lpOutputString: LPCSTR) ---
ReadConsoleW :: proc(hConsoleInput: HANDLE,
lpBuffer: LPVOID,
@@ -23,12 +22,18 @@ foreign kernel32 {
GetConsoleMode :: proc(hConsoleHandle: HANDLE,
lpMode: LPDWORD) -> BOOL ---
SetConsoleMode :: proc(hConsoleHandle: HANDLE,
dwMode: DWORD) -> BOOL ---
GetFileInformationByHandle :: proc(hFile: HANDLE, lpFileInformation: LPBY_HANDLE_FILE_INFORMATION) -> BOOL ---
SetHandleInformation :: proc(hObject: HANDLE,
dwMask: DWORD,
dwFlags: DWORD) -> BOOL ---
SetFileInformationByHandle :: proc(hFile: HANDLE,
FileInformationClass: FILE_INFO_BY_HANDLE_CLASS,
lpFileInformation: LPVOID,
dwBufferSize: DWORD) -> BOOL ---
AddVectoredExceptionHandler :: proc(FirstHandler: ULONG, VectoredHandler: PVECTORED_EXCEPTION_HANDLER) -> LPVOID ---
AddVectoredContinueHandler :: proc(FirstHandler: ULONG, VectoredHandler: PVECTORED_EXCEPTION_HANDLER) -> LPVOID ---
@@ -63,6 +68,13 @@ foreign kernel32 {
GetCurrentProcessId :: proc() -> DWORD ---
GetCurrentThread :: proc() -> HANDLE ---
GetCurrentThreadId :: proc() -> DWORD ---
GetProcessTimes :: proc(
hProcess: HANDLE,
lpCreationTime: LPFILETIME,
lpExitTime: LPFILETIME,
lpKernelTime: LPFILETIME,
lpUserTime: LPFILETIME,
) -> BOOL ---
GetStdHandle :: proc(which: DWORD) -> HANDLE ---
ExitProcess :: proc(uExitCode: c_uint) -> ! ---
DeviceIoControl :: proc(
@@ -93,6 +105,20 @@ foreign kernel32 {
CreateSemaphoreW :: proc(attributes: LPSECURITY_ATTRIBUTES, initial_count, maximum_count: LONG, name: LPCSTR) -> HANDLE ---
ReleaseSemaphore :: proc(semaphore: HANDLE, release_count: LONG, previous_count: ^LONG) -> BOOL ---
CreateWaitableTimerW :: proc(
lpTimerAttributes: LPSECURITY_ATTRIBUTES,
bManualReset: BOOL,
lpTimerName: LPCWSTR,
) -> HANDLE ---
SetWaitableTimerEx :: proc(
hTimer: HANDLE,
lpDueTime: ^LARGE_INTEGER,
lPeriod: LONG,
pfnCompletionRoutine: PTIMERAPCROUTINE,
lpArgToCompletionRoutine: LPVOID,
WakeContext: PREASON_CONTEXT,
TolerableDelay: ULONG,
) -> BOOL ---
WaitForSingleObject :: proc(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD ---
Sleep :: proc(dwMilliseconds: DWORD) ---
GetProcessId :: proc(handle: HANDLE) -> DWORD ---
@@ -218,6 +244,7 @@ foreign kernel32 {
bInitialState: BOOL,
lpName: LPCWSTR,
) -> HANDLE ---
ResetEvent :: proc(hEvent: HANDLE) -> BOOL ---
WaitForMultipleObjects :: proc(
nCount: DWORD,
lpHandles: ^HANDLE,
@@ -246,6 +273,22 @@ foreign kernel32 {
HeapReAlloc :: proc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID ---
HeapFree :: proc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL ---
LocalAlloc :: proc(flags: UINT, bytes: SIZE_T) -> LPVOID ---
LocalReAlloc :: proc(mem: LPVOID, bytes: SIZE_T, flags: UINT) -> LPVOID ---
LocalFree :: proc(mem: LPVOID) -> LPVOID ---
ReadDirectoryChangesW :: proc(
hDirectory: HANDLE,
lpBuffer: LPVOID,
nBufferLength: DWORD,
bWatchSubtree: BOOL,
dwNotifyFilter: DWORD,
lpBytesReturned: LPDWORD,
lpOverlapped: LPOVERLAPPED,
lpCompletionRoutine: LPOVERLAPPED_COMPLETION_ROUTINE,
) -> BOOL ---
InitializeSRWLock :: proc(SRWLock: ^SRWLOCK) ---
AcquireSRWLockExclusive :: proc(SRWLock: ^SRWLOCK) ---
TryAcquireSRWLockExclusive :: proc(SRWLock: ^SRWLOCK) -> BOOL ---
@@ -738,3 +781,18 @@ foreign kernel32 {
UnmapFlags: ULONG,
) -> BOOL ---
}
@(default_calling_convention="stdcall")
foreign kernel32 {
@(link_name="SetConsoleCtrlHandler") set_console_ctrl_handler :: proc(handler: Handler_Routine, add: BOOL) -> BOOL ---
}
Handler_Routine :: proc(dwCtrlType: Control_Event) -> BOOL
Control_Event :: enum DWORD {
control_c = 0,
_break = 1,
close = 2,
logoff = 5,
shutdown = 6,
}
+2 -2
View File
@@ -3,7 +3,7 @@ package sys_windows
foreign import ntdll_lib "system:ntdll.lib"
@(default_calling_convention="std")
@(default_calling_convention="stdcall")
foreign ntdll_lib {
RtlGetVersion :: proc(lpVersionInformation: ^OSVERSIONINFOEXW) -> NTSTATUS ---
RtlGetVersion :: proc(lpVersionInformation: ^OSVERSIONINFOEXW) -> NTSTATUS ---
}
+18
View File
@@ -0,0 +1,18 @@
// +build windows
package sys_windows
foreign import "system:Ole32.lib"
//objbase.h
COINIT :: enum DWORD {
APARTMENTTHREADED = 0x2,
MULTITHREADED,
DISABLE_OLE1DDE = 0x4,
SPEED_OVER_MEMORY = 0x8,
}
@(default_calling_convention="stdcall")
foreign Ole32 {
CoInitializeEx :: proc(reserved: rawptr, co_init: COINIT) -> HRESULT ---
CoUninitialize :: proc() ---
}
+1 -1
View File
@@ -3,7 +3,7 @@ package sys_windows
foreign import shell32 "system:Shell32.lib"
@(default_calling_convention = "std")
@(default_calling_convention="stdcall")
foreign shell32 {
CommandLineToArgvW :: proc(cmd_list: wstring, num_args: ^c_int) -> ^wstring ---
}
+11
View File
@@ -0,0 +1,11 @@
// +build windows
package sys_windows
foreign import shlwapi "system:shlwapi.lib"
@(default_calling_convention="stdcall")
foreign shlwapi {
PathFileExistsW :: proc(pszPath: wstring) -> BOOL ---
PathFindExtensionW :: proc(pszPath: wstring) -> wstring ---
PathFindFileNameW :: proc(pszPath: wstring) -> wstring ---
}
+2 -2
View File
@@ -5,7 +5,7 @@ foreign import Synchronization "system:Synchronization.lib"
@(default_calling_convention="stdcall")
foreign Synchronization {
WaitOnAddress :: proc(Address: PVOID, CompareAddress: PVOID, AddressSize: SIZE_T, dwMilliseconds: DWORD) -> BOOL ---
WaitOnAddress :: proc(Address: PVOID, CompareAddress: PVOID, AddressSize: SIZE_T, dwMilliseconds: DWORD) -> BOOL ---
WakeByAddressSingle :: proc(Address: PVOID) ---
WakeByAddressAll :: proc(Address: PVOID) ---
WakeByAddressAll :: proc(Address: PVOID) ---
}
+271
View File
@@ -0,0 +1,271 @@
// +build windows
package sys_windows
// Parameter for SystemParametersInfo.
SPI_GETBEEP :: 0x0001
SPI_SETBEEP :: 0x0002
SPI_GETMOUSE :: 0x0003
SPI_SETMOUSE :: 0x0004
SPI_GETBORDER :: 0x0005
SPI_SETBORDER :: 0x0006
SPI_GETKEYBOARDSPEED :: 0x000A
SPI_SETKEYBOARDSPEED :: 0x000B
SPI_LANGDRIVER :: 0x000C
SPI_ICONHORIZONTALSPACING :: 0x000D
SPI_GETSCREENSAVETIMEOUT :: 0x000E
SPI_SETSCREENSAVETIMEOUT :: 0x000F
SPI_GETSCREENSAVEACTIVE :: 0x0010
SPI_SETSCREENSAVEACTIVE :: 0x0011
SPI_GETGRIDGRANULARITY :: 0x0012
SPI_SETGRIDGRANULARITY :: 0x0013
SPI_SETDESKWALLPAPER :: 0x0014
SPI_SETDESKPATTERN :: 0x0015
SPI_GETKEYBOARDDELAY :: 0x0016
SPI_SETKEYBOARDDELAY :: 0x0017
SPI_ICONVERTICALSPACING :: 0x0018
SPI_GETICONTITLEWRAP :: 0x0019
SPI_SETICONTITLEWRAP :: 0x001A
SPI_GETMENUDROPALIGNMENT :: 0x001B
SPI_SETMENUDROPALIGNMENT :: 0x001C
SPI_SETDOUBLECLKWIDTH :: 0x001D
SPI_SETDOUBLECLKHEIGHT :: 0x001E
SPI_GETICONTITLELOGFONT :: 0x001F
SPI_SETDOUBLECLICKTIME :: 0x0020
SPI_SETMOUSEBUTTONSWAP :: 0x0021
SPI_SETICONTITLELOGFONT :: 0x0022
SPI_GETFASTTASKSWITCH :: 0x0023
SPI_SETFASTTASKSWITCH :: 0x0024
SPI_SETDRAGFULLWINDOWS :: 0x0025
SPI_GETDRAGFULLWINDOWS :: 0x0026
SPI_GETNONCLIENTMETRICS :: 0x0029
SPI_SETNONCLIENTMETRICS :: 0x002A
SPI_GETMINIMIZEDMETRICS :: 0x002B
SPI_SETMINIMIZEDMETRICS :: 0x002C
SPI_GETICONMETRICS :: 0x002D
SPI_SETICONMETRICS :: 0x002E
SPI_SETWORKAREA :: 0x002F
SPI_GETWORKAREA :: 0x0030
SPI_SETPENWINDOWS :: 0x0031
SPI_GETHIGHCONTRAST :: 0x0042
SPI_SETHIGHCONTRAST :: 0x0043
SPI_GETKEYBOARDPREF :: 0x0044
SPI_SETKEYBOARDPREF :: 0x0045
SPI_GETSCREENREADER :: 0x0046
SPI_SETSCREENREADER :: 0x0047
SPI_GETANIMATION :: 0x0048
SPI_SETANIMATION :: 0x0049
SPI_GETFONTSMOOTHING :: 0x004A
SPI_SETFONTSMOOTHING :: 0x004B
SPI_SETDRAGWIDTH :: 0x004C
SPI_SETDRAGHEIGHT :: 0x004D
SPI_SETHANDHELD :: 0x004E
SPI_GETLOWPOWERTIMEOUT :: 0x004F
SPI_GETPOWEROFFTIMEOUT :: 0x0050
SPI_SETLOWPOWERTIMEOUT :: 0x0051
SPI_SETPOWEROFFTIMEOUT :: 0x0052
SPI_GETLOWPOWERACTIVE :: 0x0053
SPI_GETPOWEROFFACTIVE :: 0x0054
SPI_SETLOWPOWERACTIVE :: 0x0055
SPI_SETPOWEROFFACTIVE :: 0x0056
SPI_SETCURSORS :: 0x0057
SPI_SETICONS :: 0x0058
SPI_GETDEFAULTINPUTLANG :: 0x0059
SPI_SETDEFAULTINPUTLANG :: 0x005A
SPI_SETLANGTOGGLE :: 0x005B
SPI_GETWINDOWSEXTENSION :: 0x005C
SPI_SETMOUSETRAILS :: 0x005D
SPI_GETMOUSETRAILS :: 0x005E
SPI_SETSCREENSAVERRUNNING :: 0x0061
SPI_SCREENSAVERRUNNING :: SPI_SETSCREENSAVERRUNNING
SPI_GETFILTERKEYS :: 0x0032
SPI_SETFILTERKEYS :: 0x0033
SPI_GETTOGGLEKEYS :: 0x0034
SPI_SETTOGGLEKEYS :: 0x0035
SPI_GETMOUSEKEYS :: 0x0036
SPI_SETMOUSEKEYS :: 0x0037
SPI_GETSHOWSOUNDS :: 0x0038
SPI_SETSHOWSOUNDS :: 0x0039
SPI_GETSTICKYKEYS :: 0x003A
SPI_SETSTICKYKEYS :: 0x003B
SPI_GETACCESSTIMEOUT :: 0x003C
SPI_SETACCESSTIMEOUT :: 0x003D
SPI_GETSERIALKEYS :: 0x003E
SPI_SETSERIALKEYS :: 0x003F
SPI_GETSOUNDSENTRY :: 0x0040
SPI_SETSOUNDSENTRY :: 0x0041
SPI_GETSNAPTODEFBUTTON :: 0x005F
SPI_SETSNAPTODEFBUTTON :: 0x0060
SPI_GETMOUSEHOVERWIDTH :: 0x0062
SPI_SETMOUSEHOVERWIDTH :: 0x0063
SPI_GETMOUSEHOVERHEIGHT :: 0x0064
SPI_SETMOUSEHOVERHEIGHT :: 0x0065
SPI_GETMOUSEHOVERTIME :: 0x0066
SPI_SETMOUSEHOVERTIME :: 0x0067
SPI_GETWHEELSCROLLLINES :: 0x0068
SPI_SETWHEELSCROLLLINES :: 0x0069
SPI_GETMENUSHOWDELAY :: 0x006A
SPI_SETMENUSHOWDELAY :: 0x006B
SPI_GETWHEELSCROLLCHARS :: 0x006C
SPI_SETWHEELSCROLLCHARS :: 0x006D
SPI_GETSHOWIMEUI :: 0x006E
SPI_SETSHOWIMEUI :: 0x006F
SPI_GETMOUSESPEED :: 0x0070
SPI_SETMOUSESPEED :: 0x0071
SPI_GETSCREENSAVERRUNNING :: 0x0072
SPI_GETDESKWALLPAPER :: 0x0073
SPI_GETAUDIODESCRIPTION :: 0x0074
SPI_SETAUDIODESCRIPTION :: 0x0075
SPI_GETSCREENSAVESECURE :: 0x0076
SPI_SETSCREENSAVESECURE :: 0x0077
SPI_GETHUNGAPPTIMEOUT :: 0x0078
SPI_SETHUNGAPPTIMEOUT :: 0x0079
SPI_GETWAITTOKILLTIMEOUT :: 0x007A
SPI_SETWAITTOKILLTIMEOUT :: 0x007B
SPI_GETWAITTOKILLSERVICETIMEOUT :: 0x007C
SPI_SETWAITTOKILLSERVICETIMEOUT :: 0x007D
SPI_GETMOUSEDOCKTHRESHOLD :: 0x007E
SPI_SETMOUSEDOCKTHRESHOLD :: 0x007F
SPI_GETPENDOCKTHRESHOLD :: 0x0080
SPI_SETPENDOCKTHRESHOLD :: 0x0081
SPI_GETWINARRANGING :: 0x0082
SPI_SETWINARRANGING :: 0x0083
SPI_GETMOUSEDRAGOUTTHRESHOLD :: 0x0084
SPI_SETMOUSEDRAGOUTTHRESHOLD :: 0x0085
SPI_GETPENDRAGOUTTHRESHOLD :: 0x0086
SPI_SETPENDRAGOUTTHRESHOLD :: 0x0087
SPI_GETMOUSESIDEMOVETHRESHOLD :: 0x0088
SPI_SETMOUSESIDEMOVETHRESHOLD :: 0x0089
SPI_GETPENSIDEMOVETHRESHOLD :: 0x008A
SPI_SETPENSIDEMOVETHRESHOLD :: 0x008B
SPI_GETDRAGFROMMAXIMIZE :: 0x008C
SPI_SETDRAGFROMMAXIMIZE :: 0x008D
SPI_GETSNAPSIZING :: 0x008E
SPI_SETSNAPSIZING :: 0x008F
SPI_GETDOCKMOVING :: 0x0090
SPI_SETDOCKMOVING :: 0x0091
SPI_GETACTIVEWINDOWTRACKING :: 0x1000
SPI_SETACTIVEWINDOWTRACKING :: 0x1001
SPI_GETMENUANIMATION :: 0x1002
SPI_SETMENUANIMATION :: 0x1003
SPI_GETCOMBOBOXANIMATION :: 0x1004
SPI_SETCOMBOBOXANIMATION :: 0x1005
SPI_GETLISTBOXSMOOTHSCROLLING :: 0x1006
SPI_SETLISTBOXSMOOTHSCROLLING :: 0x1007
SPI_GETGRADIENTCAPTIONS :: 0x1008
SPI_SETGRADIENTCAPTIONS :: 0x1009
SPI_GETKEYBOARDCUES :: 0x100A
SPI_SETKEYBOARDCUES :: 0x100B
SPI_GETMENUUNDERLINES :: SPI_GETKEYBOARDCUES
SPI_SETMENUUNDERLINES :: SPI_SETKEYBOARDCUES
SPI_GETACTIVEWNDTRKZORDER :: 0x100C
SPI_SETACTIVEWNDTRKZORDER :: 0x100D
SPI_GETHOTTRACKING :: 0x100E
SPI_SETHOTTRACKING :: 0x100F
SPI_GETMENUFADE :: 0x1012
SPI_SETMENUFADE :: 0x1013
SPI_GETSELECTIONFADE :: 0x1014
SPI_SETSELECTIONFADE :: 0x1015
SPI_GETTOOLTIPANIMATION :: 0x1016
SPI_SETTOOLTIPANIMATION :: 0x1017
SPI_GETTOOLTIPFADE :: 0x1018
SPI_SETTOOLTIPFADE :: 0x1019
SPI_GETCURSORSHADOW :: 0x101A
SPI_SETCURSORSHADOW :: 0x101B
SPI_GETMOUSESONAR :: 0x101C
SPI_SETMOUSESONAR :: 0x101D
SPI_GETMOUSECLICKLOCK :: 0x101E
SPI_SETMOUSECLICKLOCK :: 0x101F
SPI_GETMOUSEVANISH :: 0x1020
SPI_SETMOUSEVANISH :: 0x1021
SPI_GETFLATMENU :: 0x1022
SPI_SETFLATMENU :: 0x1023
SPI_GETDROPSHADOW :: 0x1024
SPI_SETDROPSHADOW :: 0x1025
SPI_GETBLOCKSENDINPUTRESETS :: 0x1026
SPI_SETBLOCKSENDINPUTRESETS :: 0x1027
SPI_GETUIEFFECTS :: 0x103E
SPI_SETUIEFFECTS :: 0x103F
SPI_GETDISABLEOVERLAPPEDCONTENT :: 0x1040
SPI_SETDISABLEOVERLAPPEDCONTENT :: 0x1041
SPI_GETCLIENTAREAANIMATION :: 0x1042
SPI_SETCLIENTAREAANIMATION :: 0x1043
SPI_GETCLEARTYPE :: 0x1048
SPI_SETCLEARTYPE :: 0x1049
SPI_GETSPEECHRECOGNITION :: 0x104A
SPI_SETSPEECHRECOGNITION :: 0x104B
SPI_GETCARETBROWSING :: 0x104C
SPI_SETCARETBROWSING :: 0x104D
SPI_GETTHREADLOCALINPUTSETTINGS :: 0x104E
SPI_SETTHREADLOCALINPUTSETTINGS :: 0x104F
SPI_GETSYSTEMLANGUAGEBAR :: 0x1050
SPI_SETSYSTEMLANGUAGEBAR :: 0x1051
SPI_GETFOREGROUNDLOCKTIMEOUT :: 0x2000
SPI_SETFOREGROUNDLOCKTIMEOUT :: 0x2001
SPI_GETACTIVEWNDTRKTIMEOUT :: 0x2002
SPI_SETACTIVEWNDTRKTIMEOUT :: 0x2003
SPI_GETFOREGROUNDFLASHCOUNT :: 0x2004
SPI_SETFOREGROUNDFLASHCOUNT :: 0x2005
SPI_GETCARETWIDTH :: 0x2006
SPI_SETCARETWIDTH :: 0x2007
SPI_GETMOUSECLICKLOCKTIME :: 0x2008
SPI_SETMOUSECLICKLOCKTIME :: 0x2009
SPI_GETFONTSMOOTHINGTYPE :: 0x200A
SPI_SETFONTSMOOTHINGTYPE :: 0x200B
// constants for SPI_GETFONTSMOOTHINGTYPE and SPI_SETFONTSMOOTHINGTYPE:
FE_FONTSMOOTHINGSTANDARD :: 0x0001
FE_FONTSMOOTHINGCLEARTYPE :: 0x0002
SPI_GETFONTSMOOTHINGCONTRAST :: 0x200C
SPI_SETFONTSMOOTHINGCONTRAST :: 0x200D
SPI_GETFOCUSBORDERWIDTH :: 0x200E
SPI_SETFOCUSBORDERWIDTH :: 0x200F
SPI_GETFOCUSBORDERHEIGHT :: 0x2010
SPI_SETFOCUSBORDERHEIGHT :: 0x2011
SPI_GETFONTSMOOTHINGORIENTATION :: 0x2012
SPI_SETFONTSMOOTHINGORIENTATION :: 0x2013
// constants for SPI_GETFONTSMOOTHINGORIENTATION and SPI_SETFONTSMOOTHINGORIENTATION:
FE_FONTSMOOTHINGORIENTATIONBGR :: 0x0000
FE_FONTSMOOTHINGORIENTATIONRGB :: 0x0001
SPI_GETMINIMUMHITRADIUS :: 0x2014
SPI_SETMINIMUMHITRADIUS :: 0x2015
SPI_GETMESSAGEDURATION :: 0x2016
SPI_SETMESSAGEDURATION :: 0x2017
SPI_GETCONTACTVISUALIZATION :: 0x2018
SPI_SETCONTACTVISUALIZATION :: 0x2019
// constants for SPI_GETCONTACTVISUALIZATION and SPI_SETCONTACTVISUALIZATION
CONTACTVISUALIZATION_OFF :: 0x0000
CONTACTVISUALIZATION_ON :: 0x0001
CONTACTVISUALIZATION_PRESENTATIONMODE :: 0x0002
SPI_GETGESTUREVISUALIZATION :: 0x201A
SPI_SETGESTUREVISUALIZATION :: 0x201B
// constants for SPI_GETGESTUREVISUALIZATION and SPI_SETGESTUREVISUALIZATION
GESTUREVISUALIZATION_OFF :: 0x0000
GESTUREVISUALIZATION_ON :: 0x001F
GESTUREVISUALIZATION_TAP :: 0x0001
GESTUREVISUALIZATION_DOUBLETAP :: 0x0002
GESTUREVISUALIZATION_PRESSANDTAP :: 0x0004
GESTUREVISUALIZATION_PRESSANDHOLD :: 0x0008
GESTUREVISUALIZATION_RIGHTTAP :: 0x0010
SPI_GETMOUSEWHEELROUTING :: 0x201C
SPI_SETMOUSEWHEELROUTING :: 0x201D
MOUSEWHEEL_ROUTING_FOCUS :: 0
MOUSEWHEEL_ROUTING_HYBRID :: 1
MOUSEWHEEL_ROUTING_MOUSE_POS :: 2
// Flags
SPIF_UPDATEINIFILE :: 0x0001
SPIF_SENDWININICHANGE :: 0x0002
SPIF_SENDCHANGE :: SPIF_SENDWININICHANGE
+262 -14
View File
@@ -3,19 +3,21 @@ package sys_windows
import "core:c"
c_char :: c.char
c_uchar :: c.uchar
c_int :: c.int
c_uint :: c.uint
c_long :: c.long
c_longlong :: c.longlong
c_ulong :: c.ulong
c_short :: c.short
c_ushort :: c.ushort
size_t :: c.size_t
wchar_t :: c.wchar_t
c_char :: c.char
c_uchar :: c.uchar
c_int :: c.int
c_uint :: c.uint
c_long :: c.long
c_longlong :: c.longlong
c_ulong :: c.ulong
c_ulonglong :: c.ulonglong
c_short :: c.short
c_ushort :: c.ushort
size_t :: c.size_t
wchar_t :: c.wchar_t
DWORD :: c_ulong
QWORD :: c.ulonglong
HANDLE :: distinct LPVOID
HINSTANCE :: HANDLE
HMODULE :: distinct HINSTANCE
@@ -55,6 +57,8 @@ UINT_PTR :: uintptr
ULONG :: c_ulong
UCHAR :: BYTE
NTSTATUS :: c.long
COLORREF :: DWORD
LPCOLORREF :: ^COLORREF
LPARAM :: LONG_PTR
WPARAM :: UINT_PTR
LRESULT :: LONG_PTR
@@ -123,6 +127,8 @@ PCONDITION_VARIABLE :: ^CONDITION_VARIABLE
PLARGE_INTEGER :: ^LARGE_INTEGER
PSRWLOCK :: ^SRWLOCK
MMRESULT :: UINT
SOCKET :: distinct uintptr // TODO
socklen_t :: c_int
ADDRESS_FAMILY :: USHORT
@@ -160,6 +166,21 @@ FILE_GENERIC_ALL: DWORD : 0x10000000
FILE_GENERIC_EXECUTE: DWORD : 0x20000000
FILE_GENERIC_READ: DWORD : 0x80000000
FILE_ACTION_ADDED :: 0x00000001
FILE_ACTION_REMOVED :: 0x00000002
FILE_ACTION_MODIFIED :: 0x00000003
FILE_ACTION_RENAMED_OLD_NAME :: 0x00000004
FILE_ACTION_RENAMED_NEW_NAME :: 0x00000005
FILE_NOTIFY_CHANGE_FILE_NAME :: 0x00000001
FILE_NOTIFY_CHANGE_DIR_NAME :: 0x00000002
FILE_NOTIFY_CHANGE_ATTRIBUTES :: 0x00000004
FILE_NOTIFY_CHANGE_SIZE :: 0x00000008
FILE_NOTIFY_CHANGE_LAST_WRITE :: 0x00000010
FILE_NOTIFY_CHANGE_LAST_ACCESS :: 0x00000020
FILE_NOTIFY_CHANGE_CREATION :: 0x00000040
FILE_NOTIFY_CHANGE_SECURITY :: 0x00000100
CREATE_NEW: DWORD : 1
CREATE_ALWAYS: DWORD : 2
OPEN_ALWAYS: DWORD : 4
@@ -172,6 +193,7 @@ FILE_WRITE_DATA: DWORD : 0x00000002
FILE_APPEND_DATA: DWORD : 0x00000004
FILE_WRITE_EA: DWORD : 0x00000010
FILE_WRITE_ATTRIBUTES: DWORD : 0x00000100
FILE_READ_ATTRIBUTES: DWORD : 0x000000080
READ_CONTROL: DWORD : 0x00020000
SYNCHRONIZE: DWORD : 0x00100000
GENERIC_READ: DWORD : 0x80000000
@@ -195,6 +217,56 @@ GET_FILEEX_INFO_LEVELS :: distinct i32
GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS : 0
GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS : 1
// String resource number bases (internal use)
MMSYSERR_BASE :: 0
WAVERR_BASE :: 32
MIDIERR_BASE :: 64
TIMERR_BASE :: 96
JOYERR_BASE :: 160
MCIERR_BASE :: 256
MIXERR_BASE :: 1024
MCI_STRING_OFFSET :: 512
MCI_VD_OFFSET :: 1024
MCI_CD_OFFSET :: 1088
MCI_WAVE_OFFSET :: 1152
MCI_SEQ_OFFSET :: 1216
// timer error return values
TIMERR_NOERROR :: 0 // no error
TIMERR_NOCANDO :: TIMERR_BASE + 1 // request not completed
TIMERR_STRUCT :: TIMERR_BASE + 33 // time struct size
DIAGNOSTIC_REASON_VERSION :: 0
DIAGNOSTIC_REASON_SIMPLE_STRING :: 0x00000001
DIAGNOSTIC_REASON_DETAILED_STRING :: 0x00000002
DIAGNOSTIC_REASON_NOT_SPECIFIED :: 0x80000000
// Defines for power request APIs
POWER_REQUEST_CONTEXT_VERSION :: DIAGNOSTIC_REASON_VERSION
POWER_REQUEST_CONTEXT_SIMPLE_STRING :: DIAGNOSTIC_REASON_SIMPLE_STRING
POWER_REQUEST_CONTEXT_DETAILED_STRING :: DIAGNOSTIC_REASON_DETAILED_STRING
REASON_CONTEXT :: struct {
Version: ULONG,
Flags: DWORD,
Reason: struct #raw_union {
Detailed: struct {
LocalizedReasonModule: HMODULE,
LocalizedReasonId: ULONG,
ReasonStringCount: ULONG,
ReasonStrings: ^LPWSTR,
},
SimpleReasonString: LPWSTR,
},
}
PREASON_CONTEXT :: ^REASON_CONTEXT
PTIMERAPCROUTINE :: #type proc "stdcall" (lpArgToCompletionRoutine: LPVOID, dwTimerLowValue, dwTimerHighValue: DWORD)
TIMERPROC :: #type proc "stdcall" (HWND, UINT, UINT_PTR, DWORD)
@@ -734,6 +806,10 @@ HOVER_DEFAULT :: 0xFFFFFFFF
USER_TIMER_MAXIMUM :: 0x7FFFFFFF
USER_TIMER_MINIMUM :: 0x0000000A
// WM_ACTIVATE state values
WA_INACTIVE :: 0
WA_ACTIVE :: 1
WA_CLICKACTIVE :: 2
// SetWindowsHook() codes
WH_MIN :: -1
@@ -1066,6 +1142,7 @@ ERROR_BROKEN_PIPE: DWORD : 109
ERROR_CALL_NOT_IMPLEMENTED: DWORD : 120
ERROR_INSUFFICIENT_BUFFER: DWORD : 122
ERROR_INVALID_NAME: DWORD : 123
ERROR_BAD_ARGUMENTS: DWORD: 160
ERROR_LOCK_FAILED: DWORD : 167
ERROR_ALREADY_EXISTS: DWORD : 183
ERROR_NO_DATA: DWORD : 232
@@ -1082,9 +1159,21 @@ INVALID_HANDLE_VALUE :: INVALID_HANDLE
FACILITY_NT_BIT: DWORD : 0x1000_0000
FORMAT_MESSAGE_FROM_SYSTEM: DWORD : 0x00001000
FORMAT_MESSAGE_FROM_HMODULE: DWORD : 0x00000800
FORMAT_MESSAGE_IGNORE_INSERTS: DWORD : 0x00000200
FORMAT_MESSAGE_ALLOCATE_BUFFER :: 0x00000100
FORMAT_MESSAGE_IGNORE_INSERTS :: 0x00000200
FORMAT_MESSAGE_FROM_STRING :: 0x00000400
FORMAT_MESSAGE_FROM_HMODULE :: 0x00000800
FORMAT_MESSAGE_FROM_SYSTEM :: 0x00001000
FORMAT_MESSAGE_ARGUMENT_ARRAY :: 0x00002000
FORMAT_MESSAGE_MAX_WIDTH_MASK :: 0x000000FF
LMEM_FIXED :: 0x0000
LMEM_MOVEABLE :: 0x0002
LMEM_ZEROINIT :: 0x0040
LHND :: 0x0042
LPTR :: 0x0040
NONZEROLHND :: LMEM_MOVEABLE
NONZEROLPTR :: LMEM_FIXED
TLS_OUT_OF_INDEXES: DWORD : 0xFFFFFFFF
@@ -1307,6 +1396,13 @@ FILE_END_OF_FILE_INFO :: struct {
EndOfFile: LARGE_INTEGER,
}
FILE_NOTIFY_INFORMATION :: struct {
next_entry_offset: DWORD,
action: DWORD,
file_name_length: DWORD,
file_name: [1]WCHAR,
}
REPARSE_DATA_BUFFER :: struct {
ReparseTag: c_uint,
ReparseDataLength: c_ushort,
@@ -1451,6 +1547,12 @@ OVERLAPPED :: struct {
hEvent: HANDLE,
}
LPOVERLAPPED_COMPLETION_ROUTINE :: #type proc "stdcall" (
dwErrorCode: DWORD,
dwNumberOfBytesTransfered: DWORD,
lpOverlapped: LPOVERLAPPED,
)
ADDRESS_MODE :: enum c_int {
AddrMode1616,
AddrMode1632,
@@ -1476,6 +1578,33 @@ ADDRINFOA :: struct {
ai_next: ^ADDRINFOA,
}
PADDRINFOEXW :: ^ADDRINFOEXW
LPADDRINFOEXW :: ^ADDRINFOEXW
ADDRINFOEXW :: struct {
ai_flags: c_int,
ai_family: c_int,
ai_socktype: c_int,
ai_protocol: c_int,
ai_addrlen: size_t,
ai_canonname: wstring,
ai_addr: ^sockaddr,
ai_blob: rawptr,
ai_bloblen: size_t,
ai_provider: LPGUID,
ai_next: ^ADDRINFOEXW,
}
LPLOOKUPSERVICE_COMPLETION_ROUTINE :: #type proc "stdcall" (
dwErrorCode: DWORD,
dwNumberOfBytesTransfered: DWORD,
lpOverlapped: LPOVERLAPPED,
)
sockaddr :: struct {
sa_family: USHORT,
sa_data: [14]byte,
}
sockaddr_in :: struct {
sin_family: ADDRESS_FAMILY,
sin_port: USHORT,
@@ -2082,3 +2211,122 @@ SYSTEMTIME :: struct {
second: WORD,
milliseconds: WORD,
}
@(private="file")
IMAGE_DOS_HEADER :: struct {
e_magic: WORD,
e_cblp: WORD,
e_cp: WORD,
e_crlc: WORD,
e_cparhdr: WORD,
e_minalloc: WORD,
e_maxalloc: WORD,
e_ss: WORD,
e_sp: WORD,
e_csum: WORD,
e_ip: WORD,
e_cs: WORD,
e_lfarlc: WORD,
e_ovno: WORD,
e_res_0: WORD,
e_res_1: WORD,
e_res_2: WORD,
e_res_3: WORD,
e_oemid: WORD,
e_oeminfo: WORD,
e_res2_0: WORD,
e_res2_1: WORD,
e_res2_2: WORD,
e_res2_3: WORD,
e_res2_4: WORD,
e_res2_5: WORD,
e_res2_6: WORD,
e_res2_7: WORD,
e_res2_8: WORD,
e_res2_9: WORD,
e_lfanew: DWORD,
}
IMAGE_DATA_DIRECTORY :: struct {
VirtualAddress: DWORD,
Size: DWORD,
}
IMAGE_FILE_HEADER :: struct {
Machine: WORD,
NumberOfSections: WORD,
TimeDateStamp: DWORD,
PointerToSymbolTable: DWORD,
NumberOfSymbols: DWORD,
SizeOfOptionalHeader: WORD,
Characteristics: WORD,
}
IMAGE_OPTIONAL_HEADER64 :: struct {
Magic: WORD,
MajorLinkerVersion: BYTE,
MinorLinkerVersion: BYTE,
SizeOfCode: DWORD,
SizeOfInitializedData: DWORD,
SizeOfUninitializedData: DWORD,
AddressOfEntryPoint: DWORD,
BaseOfCode: DWORD,
ImageBase: QWORD,
SectionAlignment: DWORD,
FileAlignment: DWORD,
MajorOperatingSystemVersion: WORD,
MinorOperatingSystemVersion: WORD,
MajorImageVersion: WORD,
MinorImageVersion: WORD,
MajorSubsystemVersion: WORD,
MinorSubsystemVersion: WORD,
Win32VersionValue: DWORD,
SizeOfImage: DWORD,
SizeOfHeaders: DWORD,
CheckSum: DWORD,
Subsystem: WORD,
DllCharacteristics: WORD,
SizeOfStackReserve: QWORD,
SizeOfStackCommit: QWORD,
SizeOfHeapReserve: QWORD,
SizeOfHeapCommit: QWORD,
LoaderFlags: DWORD,
NumberOfRvaAndSizes: DWORD,
ExportTable: IMAGE_DATA_DIRECTORY,
ImportTable: IMAGE_DATA_DIRECTORY,
ResourceTable: IMAGE_DATA_DIRECTORY,
ExceptionTable: IMAGE_DATA_DIRECTORY,
CertificateTable: IMAGE_DATA_DIRECTORY,
BaseRelocationTable: IMAGE_DATA_DIRECTORY,
Debug: IMAGE_DATA_DIRECTORY,
Architecture: IMAGE_DATA_DIRECTORY,
GlobalPtr: IMAGE_DATA_DIRECTORY,
TLSTable: IMAGE_DATA_DIRECTORY,
LoadConfigTable: IMAGE_DATA_DIRECTORY,
BoundImport: IMAGE_DATA_DIRECTORY,
IAT: IMAGE_DATA_DIRECTORY,
DelayImportDescriptor: IMAGE_DATA_DIRECTORY,
CLRRuntimeHeader: IMAGE_DATA_DIRECTORY,
Reserved: IMAGE_DATA_DIRECTORY,
}
IMAGE_NT_HEADERS64 :: struct {
Signature: DWORD,
FileHeader: IMAGE_FILE_HEADER,
OptionalHeader: IMAGE_OPTIONAL_HEADER64,
}
IMAGE_EXPORT_DIRECTORY :: struct {
Characteristics: DWORD,
TimeDateStamp: DWORD,
MajorVersion: WORD,
MinorVersion: WORD,
Name: DWORD,
Base: DWORD,
NumberOfFunctions: DWORD,
NumberOfNames: DWORD,
AddressOfFunctions: DWORD, // RVA from base of image
AddressOfNames: DWORD, // RVA from base of image
AddressOfNameOrdinals: DWORD, // RVA from base of image
}
+16 -65
View File
@@ -5,43 +5,20 @@ foreign import user32 "system:User32.lib"
@(default_calling_convention="stdcall")
foreign user32 {
GetClassInfoA :: proc(hInstance: HINSTANCE, lpClassNAme: LPCSTR, lpWndClass: ^WNDCLASSA) -> BOOL ---
GetClassInfoW :: proc(hInstance: HINSTANCE, lpClassNAme: LPCWSTR, lpWndClass: ^WNDCLASSW) -> BOOL ---
GetClassInfoExA :: proc(hInsatnce: HINSTANCE, lpszClass: LPCSTR, lpwcx: ^WNDCLASSEXA) -> BOOL ---
GetClassInfoExW :: proc(hInsatnce: HINSTANCE, lpszClass: LPCWSTR, lpwcx: ^WNDCLASSEXW) -> BOOL ---
GetClassLongA :: proc(hWnd: HWND, nIndex: c_int) -> DWORD ---
GetClassLongW :: proc(hWnd: HWND, nIndex: c_int) -> DWORD ---
SetClassLongA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> DWORD ---
SetClassLongW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> DWORD ---
GetWindowLongA :: proc(hWnd: HWND, nIndex: c_int) -> LONG ---
GetWindowLongW :: proc(hWnd: HWND, nIndex: c_int) -> LONG ---
SetWindowLongA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> LONG ---
SetWindowLongW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> LONG ---
GetClassNameA :: proc(hWnd: HWND, lpClassName: LPSTR, nMaxCount: c_int) -> c_int ---
GetClassNameW :: proc(hWnd: HWND, lpClassName: LPWSTR, nMaxCount: c_int) -> c_int ---
RegisterClassA :: proc(lpWndClass: ^WNDCLASSA) -> ATOM ---
RegisterClassW :: proc(lpWndClass: ^WNDCLASSW) -> ATOM ---
RegisterClassExA :: proc(^WNDCLASSEXA) -> ATOM ---
RegisterClassExW :: proc(^WNDCLASSEXW) -> ATOM ---
CreateWindowExA :: proc(
dwExStyle: DWORD,
lpClassName: LPCSTR,
lpWindowName: LPCSTR,
dwStyle: DWORD,
X: c_int,
Y: c_int,
nWidth: c_int,
nHeight: c_int,
hWndParent: HWND,
hMenu: HMENU,
hInstance: HINSTANCE,
lpParam: LPVOID,
) -> HWND ---
CreateWindowExW :: proc(
dwExStyle: DWORD,
lpClassName: LPCWSTR,
@@ -60,12 +37,16 @@ foreign user32 {
DestroyWindow :: proc(hWnd: HWND) -> BOOL ---
ShowWindow :: proc(hWnd: HWND, nCmdShow: c_int) -> BOOL ---
BringWindowToTop :: proc(hWnd: HWND) -> BOOL ---
GetTopWindow :: proc(hWnd: HWND) -> HWND ---
SetForegroundWindow :: proc(hWnd: HWND) -> BOOL ---
GetForegroundWindow :: proc() -> HWND ---
SetActiveWindow :: proc(hWnd: HWND) -> HWND ---
GetActiveWindow :: proc() -> HWND ---
GetMessageA :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT) -> BOOL ---
GetMessageW :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT) -> BOOL ---
TranslateMessage :: proc(lpMsg: ^MSG) -> BOOL ---
DispatchMessageA :: proc(lpMsg: ^MSG) -> LRESULT ---
DispatchMessageW :: proc(lpMsg: ^MSG) -> LRESULT ---
PeekMessageA :: proc(lpMsg: ^MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT, wRemoveMsg: UINT) -> BOOL ---
@@ -99,6 +80,7 @@ foreign user32 {
GetWindowRect :: proc(hWnd: HWND, lpRect: LPRECT) -> BOOL ---
GetClientRect :: proc(hWnd: HWND, lpRect: LPRECT) -> BOOL ---
ClientToScreen :: proc(hWnd: HWND, lpPoint: LPPOINT) -> BOOL ---
ScreenToClient :: proc(hWnd: HWND, lpPoint: LPPOINT) -> BOOL ---
SetWindowPos :: proc(
hWnd: HWND,
hWndInsertAfter: HWND,
@@ -108,10 +90,13 @@ foreign user32 {
cy: c_int,
uFlags: UINT,
) -> BOOL ---
MoveWindow :: proc(hWnd: HWND, X, Y, hWidth, hHeight: c_int, bRepaint: BOOL) -> BOOL ---
GetSystemMetrics :: proc(nIndex: c_int) -> c_int ---
AdjustWindowRect :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL) -> BOOL ---
AdjustWindowRectEx :: proc(lpRect: LPRECT, dwStyle: DWORD, bMenu: BOOL, dwExStyle: DWORD) -> BOOL ---
SystemParametersInfoW :: proc(uiAction, uiParam: UINT, pvParam: PVOID, fWinIni: UINT) -> BOOL ---
GetWindowDC :: proc(hWnd: HWND) -> HDC ---
GetDC :: proc(hWnd: HWND) -> HDC ---
ReleaseDC :: proc(hWnd: HWND, hDC: HDC) -> c_int ---
@@ -131,10 +116,8 @@ foreign user32 {
GetKeyState :: proc(nVirtKey: c_int) -> SHORT ---
GetAsyncKeyState :: proc(vKey: c_int) -> SHORT ---
MapVirtualKeyA :: proc(uCode: UINT, uMapType: UINT) -> UINT ---
MapVirtualKeyW :: proc(uCode: UINT, uMapType: UINT) -> UINT ---
SetWindowsHookExA :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK ---
SetWindowsHookExW :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK ---
UnhookWindowsHookEx :: proc(hhk: HHOOK) -> BOOL ---
CallNextHookEx :: proc(hhk: HHOOK, nCode: c_int, wParam: WPARAM, lParam: LPARAM) -> LRESULT ---
@@ -142,39 +125,15 @@ foreign user32 {
SetTimer :: proc(hWnd: HWND, nIDEvent: UINT_PTR, uElapse: UINT, lpTimerFunc: TIMERPROC) -> UINT_PTR ---
KillTimer :: proc(hWnd: HWND, uIDEvent: UINT_PTR) -> BOOL ---
MessageBoxA :: proc(hWnd: HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT) -> c_int ---
// MessageBoxA :: proc(hWnd: HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT) -> c_int ---
MessageBoxW :: proc(hWnd: HWND, lpText: LPCWSTR, lpCaption: LPCWSTR, uType: UINT) -> c_int ---
MessageBoxExA :: proc(hWnd: HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT, wLanguageId: WORD) -> c_int ---
// MessageBoxExA :: proc(hWnd: HWND, lpText: LPCSTR, lpCaption: LPCSTR, uType: UINT, wLanguageId: WORD) -> c_int ---
MessageBoxExW :: proc(hWnd: HWND, lpText: LPCWSTR, lpCaption: LPCWSTR, uType: UINT, wLanguageId: WORD) -> c_int ---
}
CreateWindowA :: #force_inline proc "stdcall" (
lpClassName: LPCSTR,
lpWindowName: LPCSTR,
dwStyle: DWORD,
X: c_int,
Y: c_int,
nWidth: c_int,
nHeight: c_int,
hWndParent: HWND,
hMenu: HMENU,
hInstance: HINSTANCE,
lpParam: LPVOID,
) -> HWND {
return CreateWindowExA(
0,
lpClassName,
lpWindowName,
dwStyle,
X,
Y,
nWidth,
nHeight,
hWndParent,
hMenu,
hInstance,
lpParam,
)
ClipCursor :: proc(lpRect: LPRECT) -> BOOL ---
GetCursorPos :: proc(lpPoint: LPPOINT) -> BOOL ---
SetCursorPos :: proc(X: c_int, Y: c_int) -> BOOL ---
SetCursor :: proc(hCursor: HCURSOR) -> HCURSOR ---
}
CreateWindowW :: #force_inline proc "stdcall" (
@@ -209,25 +168,17 @@ CreateWindowW :: #force_inline proc "stdcall" (
when ODIN_ARCH == .amd64 {
@(default_calling_convention="stdcall")
foreign user32 {
GetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR ---
GetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR ---
SetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR ---
SetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR ---
GetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR ---
GetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR ---
SetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR ---
SetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR ---
}
} else when ODIN_ARCH == .i386 {
GetClassLongPtrA :: GetClassLongA
GetClassLongPtrW :: GetClassLongW
SetClassLongPtrA :: SetClassLongA
SetClassLongPtrW :: SetClassLongW
GetWindowLongPtrA :: GetWindowLongA
GetWindowLongPtrW :: GetWindowLongW
SetWindowLongPtrA :: GetWindowLongA
SetWindowLongPtrW :: GetWindowLongW
}
+37 -29
View File
@@ -2,7 +2,7 @@
package sys_windows
import "core:strings"
import "core:sys/win32"
import "core:runtime"
import "core:intrinsics"
L :: intrinsics.constant_utf16_cstring
@@ -15,6 +15,14 @@ HIWORD :: #force_inline proc "contextless" (x: DWORD) -> WORD {
return WORD(x >> 16)
}
GET_X_LPARAM :: #force_inline proc "contextless" (lp: LPARAM) -> c_int {
return cast(c_int)cast(c_short)LOWORD(cast(DWORD)lp)
}
GET_Y_LPARAM :: #force_inline proc "contextless" (lp: LPARAM) -> c_int {
return cast(c_int)cast(c_short)HIWORD(cast(DWORD)lp)
}
utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
if len(s) < 1 {
return nil
@@ -48,16 +56,16 @@ utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> wstri
return nil
}
wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator) -> (res: string) {
wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator) -> (res: string, err: runtime.Allocator_Error) {
context.allocator = allocator
if N <= 0 {
return ""
return
}
n := WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), nil, 0, nil, nil)
if n == 0 {
return ""
return
}
// If N == -1 the call to WideCharToMultiByte assume the wide string is null terminated
@@ -65,12 +73,12 @@ wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator)
// also null terminated.
// If N != -1 it assumes the wide string is not null terminated and the resulting string
// will not be null terminated, we therefore have to force it to be null terminated manually.
text := make([]byte, n+1 if N != -1 else n)
text := make([]byte, n+1 if N != -1 else n) or_return
n1 := WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), raw_data(text), n, nil, nil)
if n1 == 0 {
delete(text, allocator)
return ""
return
}
for i in 0..<n {
@@ -79,12 +87,12 @@ wstring_to_utf8 :: proc(s: wstring, N: int, allocator := context.temp_allocator)
break
}
}
return string(text[:n])
return string(text[:n]), nil
}
utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string {
utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> (res: string, err: runtime.Allocator_Error) {
if len(s) == 0 {
return ""
return "", nil
}
return wstring_to_utf8(raw_data(s), len(s), allocator)
}
@@ -208,7 +216,7 @@ get_computer_name_and_account_sid :: proc(username: string) -> (computer_name: s
if !res {
return "", {}, false
}
computer_name = utf16_to_utf8(cname_w, context.temp_allocator)
computer_name = utf16_to_utf8(cname_w, context.temp_allocator) or_else ""
ok = true
return
@@ -298,7 +306,7 @@ add_user_profile :: proc(username: string) -> (ok: bool, profile_path: string) {
if res == false {
return false, ""
}
defer win32.local_free(sb)
defer LocalFree(sb)
pszProfilePath := make([]u16, 257, context.temp_allocator)
res2 := CreateProfile(
@@ -310,7 +318,7 @@ add_user_profile :: proc(username: string) -> (ok: bool, profile_path: string) {
if res2 != 0 {
return false, ""
}
profile_path = wstring_to_utf8(&pszProfilePath[0], 257)
profile_path = wstring_to_utf8(&pszProfilePath[0], 257) or_else ""
return true, profile_path
}
@@ -328,7 +336,7 @@ delete_user_profile :: proc(username: string) -> (ok: bool) {
if res == false {
return false
}
defer win32.local_free(sb)
defer LocalFree(sb)
res2 := DeleteProfileW(
sb,
@@ -443,20 +451,20 @@ run_as_user :: proc(username, password, application, commandline: string, pi: ^P
nil, // lpProcessAttributes,
nil, // lpThreadAttributes,
false, // bInheritHandles,
0, // creation flags
nil, // environment,
nil, // current directory: inherit from parent if nil
&si,
pi,
))
if ok {
if wait {
WaitForSingleObject(pi.hProcess, INFINITE)
CloseHandle(pi.hProcess)
CloseHandle(pi.hThread)
}
return true
} else {
return false
}
0, // creation flags
nil, // environment,
nil, // current directory: inherit from parent if nil
&si,
pi,
))
if ok {
if wait {
WaitForSingleObject(pi.hProcess, INFINITE)
CloseHandle(pi.hProcess)
CloseHandle(pi.hThread)
}
return true
} else {
return false
}
}
+87
View File
@@ -0,0 +1,87 @@
// +build windows
package sys_windows
import "core:c"
foreign import "system:Opengl32.lib"
CONTEXT_MAJOR_VERSION_ARB :: 0x2091
CONTEXT_MINOR_VERSION_ARB :: 0x2092
CONTEXT_FLAGS_ARB :: 0x2094
CONTEXT_PROFILE_MASK_ARB :: 0x9126
CONTEXT_FORWARD_COMPATIBLE_BIT_ARB :: 0x0002
CONTEXT_CORE_PROFILE_BIT_ARB :: 0x00000001
CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002
HGLRC :: distinct HANDLE
LPLAYERPLANEDESCRIPTOR :: ^LAYERPLANEDESCRIPTOR
LAYERPLANEDESCRIPTOR :: struct {
nSize: WORD,
nVersion: WORD,
dwFlags: DWORD,
iPixelType: BYTE,
cColorBits: BYTE,
cRedBits: BYTE,
cRedShift: BYTE,
cGreenBits: BYTE,
cGreenShift: BYTE,
cBlueBits: BYTE,
cBlueShift: BYTE,
cAlphaBits: BYTE,
cAlphaShift: BYTE,
cAccumBits: BYTE,
cAccumRedBits: BYTE,
cAccumGreenBits: BYTE,
cAccumBlueBits: BYTE,
cAccumAlphaBits: BYTE,
cDepthBits: BYTE,
cStencilBits: BYTE,
cAuxBuffers: BYTE,
iLayerPlane: BYTE,
bReserved: BYTE,
crTransparent: COLORREF,
}
POINTFLOAT :: struct {x, y: f32}
LPGLYPHMETRICSFLOAT :: ^GLYPHMETRICSFLOAT
GLYPHMETRICSFLOAT :: struct {
gmfBlackBoxX: f32,
gmfBlackBoxY: f32,
gmfptGlyphOrigin: POINTFLOAT,
gmfCellIncX: f32,
gmfCellIncY: f32,
}
CreateContextAttribsARBType :: #type proc "c" (hdc: HDC, hShareContext: rawptr, attribList: [^]c.int) -> HGLRC
ChoosePixelFormatARBType :: #type proc "c" (hdc: HDC, attribIList: [^]c.int, attribFList: [^]f32, maxFormats: DWORD, formats: [^]c.int, numFormats: [^]DWORD) -> BOOL
SwapIntervalEXTType :: #type proc "c" (interval: c.int) -> bool
GetExtensionsStringARBType :: #type proc "c" (HDC) -> cstring
// Procedures
wglCreateContextAttribsARB: CreateContextAttribsARBType
wglChoosePixelFormatARB: ChoosePixelFormatARBType
wglSwapIntervalExt: SwapIntervalEXTType
wglGetExtensionsStringARB: GetExtensionsStringARBType
@(default_calling_convention="stdcall")
foreign Opengl32 {
wglCreateContext :: proc(hdc: HDC) -> HGLRC ---
wglMakeCurrent :: proc(hdc: HDC, HGLRC: HGLRC) -> BOOL ---
wglGetProcAddress :: proc(c_str: cstring) -> rawptr ---
wglDeleteContext :: proc(HGLRC: HGLRC) -> BOOL ---
wglCopyContext :: proc(src, dst: HGLRC, mask: UINT) -> BOOL ---
wglCreateLayerContext :: proc(hdc: HDC, layer_plane: c.int) -> HGLRC ---
wglDescribeLayerPlane :: proc(hdc: HDC, pixel_format, layer_plane: c.int, bytes: UINT, pd: LPLAYERPLANEDESCRIPTOR) -> BOOL ---
wglGetCurrentContext :: proc() -> HGLRC ---
wglGetCurrentDC :: proc() -> HDC ---
wglGetLayerPaletteEntries :: proc(hdc: HDC, layer_plane, start, entries: c.int, cr: ^COLORREF) -> c.int ---
wglRealizeLayerPalette :: proc(hdc: HDC, layer_plane: c.int, realize: BOOL) -> BOOL ---
wglSetLayerPaletteEntries :: proc(hdc: HDC, layer_plane, start, entries: c.int, cr: ^COLORREF) -> c.int ---
wglShareLists :: proc(HGLRC1, HGLRC2: HGLRC) -> BOOL ---
wglSwapLayerBuffers :: proc(hdc: HDC, planes: DWORD) -> BOOL ---
wglUseFontBitmaps :: proc(hdc: HDC, first, count, list_base: DWORD) -> BOOL ---
wglUseFontOutlines :: proc(hdc: HDC, first, count, list_base: DWORD, deviation, extrusion: f32, format: c.int, gmf: LPGLYPHMETRICSFLOAT) -> BOOL ---
}
+10
View File
@@ -0,0 +1,10 @@
// +build windows
package sys_windows
foreign import winmm "system:Winmm.lib"
@(default_calling_convention="stdcall")
foreign winmm {
timeBeginPeriod :: proc(uPeriod: UINT) -> MMRESULT ---
timeEndPeriod :: proc(uPeriod: UINT) -> MMRESULT ---
}
+13
View File
@@ -87,6 +87,19 @@ foreign ws2_32 {
res: ^^ADDRINFOA,
) -> c_int ---
freeaddrinfo :: proc(res: ^ADDRINFOA) ---
FreeAddrInfoExW :: proc(pAddrInfoEx: PADDRINFOEXW) ---
GetAddrInfoExW :: proc(
pName: PCWSTR,
pServiceName: PCWSTR,
dwNameSpace: DWORD,
lpNspId: LPGUID,
hints: ^ADDRINFOEXW,
ppResult: ^PADDRINFOEXW,
timeout: ^timeval,
lpOverlapped: LPOVERLAPPED,
lpCompletionRoutine: LPLOOKUPSERVICE_COMPLETION_ROUTINE,
lpHandle: LPHANDLE) -> INT ---
select :: proc(
nfds: c_int,
readfds: ^fd_set,