diff options
| author | jason <jkercher@rlcsystems.com> | 2022-05-16 13:49:57 -0400 |
|---|---|---|
| committer | jason <jkercher@rlcsystems.com> | 2022-05-16 13:49:57 -0400 |
| commit | fff23e2bbbd1574debce9e0dee894f3cc84a04c4 (patch) | |
| tree | 4055ea217375d34693861b39fc284e411f7c0366 /core/sys | |
| parent | 97d1a6787189d7630650612f44c393f7a635019a (diff) | |
| parent | 33895b6d927c70167f3bfa64c6cc1c15c4e428c5 (diff) | |
merge from upstream and convert to ^File types
Diffstat (limited to 'core/sys')
38 files changed, 992 insertions, 2208 deletions
diff --git a/core/sys/darwin/xnu_system_call_wrappers.odin b/core/sys/darwin/xnu_system_call_wrappers.odin index 4e4227f1f..685f75ffa 100644 --- a/core/sys/darwin/xnu_system_call_wrappers.odin +++ b/core/sys/darwin/xnu_system_call_wrappers.odin @@ -402,7 +402,7 @@ syscall_openat :: #force_inline proc(fd: int, path: cstring, oflag: u32, mode: u return cast(c.int)intrinsics.syscall(unix_offset_syscall(.openat), uintptr(fd), transmute(uintptr)path, uintptr(oflag), uintptr(mode)) } -syscall_getentropy :: #force_inline proc(buf: ^u8, buflen: u64) -> c.int { +syscall_getentropy :: #force_inline proc(buf: [^]u8, buflen: u64) -> c.int { return cast(c.int)intrinsics.syscall(unix_offset_syscall(.getentropy), uintptr(buf), uintptr(buflen)) } diff --git a/core/sys/unix/pthread_darwin.odin b/core/sys/unix/pthread_darwin.odin index 542a550cb..e138b8610 100644 --- a/core/sys/unix/pthread_darwin.odin +++ b/core/sys/unix/pthread_darwin.odin @@ -81,3 +81,16 @@ PTHREAD_MUTEX_NORMAL :: 0 PTHREAD_MUTEX_RECURSIVE :: 1 PTHREAD_MUTEX_ERRORCHECK :: 2 +PTHREAD_CANCEL_ENABLE :: 0 +PTHREAD_CANCEL_DISABLE :: 1 +PTHREAD_CANCEL_DEFERRED :: 0 +PTHREAD_CANCEL_ASYNCHRONOUS :: 1 + +foreign import pthread "System.framework" + +@(default_calling_convention="c") +foreign pthread { + pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int --- + pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int --- + pthread_cancel :: proc (thread: pthread_t) -> c.int --- +}
\ No newline at end of file diff --git a/core/sys/unix/pthread_freebsd.odin b/core/sys/unix/pthread_freebsd.odin index dd5306417..e02345cad 100644 --- a/core/sys/unix/pthread_freebsd.odin +++ b/core/sys/unix/pthread_freebsd.odin @@ -92,6 +92,11 @@ sem_t :: struct { _padding: u32, } +PTHREAD_CANCEL_ENABLE :: 0 +PTHREAD_CANCEL_DISABLE :: 1 +PTHREAD_CANCEL_DEFERRED :: 0 +PTHREAD_CANCEL_ASYNCHRONOUS :: 1 + foreign import "system:pthread" @(default_calling_convention="c") @@ -110,5 +115,8 @@ foreign pthread { // NOTE: unclear whether pthread_yield is well-supported on Linux systems, // see https://linux.die.net/man/3/pthread_yield pthread_yield :: proc() --- -} + pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int --- + pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int --- + pthread_cancel :: proc (thread: pthread_t) -> c.int --- +}
\ No newline at end of file diff --git a/core/sys/unix/pthread_linux.odin b/core/sys/unix/pthread_linux.odin index 099e7c7e9..9c297ef22 100644 --- a/core/sys/unix/pthread_linux.odin +++ b/core/sys/unix/pthread_linux.odin @@ -94,6 +94,11 @@ when size_of(int) == 8 { SEM_T_SIZE :: 16 } +PTHREAD_CANCEL_ENABLE :: 0 +PTHREAD_CANCEL_DISABLE :: 1 +PTHREAD_CANCEL_DEFERRED :: 0 +PTHREAD_CANCEL_ASYNCHRONOUS :: 1 + foreign import "system:pthread" @(default_calling_convention="c") @@ -112,4 +117,8 @@ foreign pthread { // NOTE: unclear whether pthread_yield is well-supported on Linux systems, // see https://linux.die.net/man/3/pthread_yield pthread_yield :: proc() -> c.int --- + + pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int --- + pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int --- + pthread_cancel :: proc (thread: pthread_t) -> c.int --- } diff --git a/core/sys/unix/pthread_openbsd.odin b/core/sys/unix/pthread_openbsd.odin index c855f95c0..7ae82e662 100644 --- a/core/sys/unix/pthread_openbsd.odin +++ b/core/sys/unix/pthread_openbsd.odin @@ -46,6 +46,11 @@ sched_param :: struct { sem_t :: distinct rawptr +PTHREAD_CANCEL_ENABLE :: 0 +PTHREAD_CANCEL_DISABLE :: 1 +PTHREAD_CANCEL_DEFERRED :: 0 +PTHREAD_CANCEL_ASYNCHRONOUS :: 1 + foreign import libc "system:c" @(default_calling_convention="c") @@ -62,4 +67,8 @@ foreign libc { // NOTE: unclear whether pthread_yield is well-supported on Linux systems, // see https://linux.die.net/man/3/pthread_yield pthread_yield :: proc() --- -} + + pthread_setcancelstate :: proc (state: c.int, old_state: ^c.int) -> c.int --- + pthread_setcanceltype :: proc (type: c.int, old_type: ^c.int) -> c.int --- + pthread_cancel :: proc (thread: pthread_t) -> c.int --- +}
\ No newline at end of file diff --git a/core/sys/unix/pthread_unix.odin b/core/sys/unix/pthread_unix.odin index 62e3701ab..8bf397647 100644 --- a/core/sys/unix/pthread_unix.odin +++ b/core/sys/unix/pthread_unix.odin @@ -4,7 +4,6 @@ package unix foreign import "system:pthread" import "core:c" -import "core:time" // // On success, these functions return 0. @@ -72,7 +71,7 @@ foreign pthread { // assumes the mutex is pre-locked pthread_cond_wait :: proc(cond: ^pthread_cond_t, mutex: ^pthread_mutex_t) -> c.int --- - pthread_cond_timedwait :: proc(cond: ^pthread_cond_t, mutex: ^pthread_mutex_t, timeout: ^time.TimeSpec) -> c.int --- + pthread_cond_timedwait :: proc(cond: ^pthread_cond_t, mutex: ^pthread_mutex_t, timeout: ^timespec) -> c.int --- pthread_condattr_init :: proc(attrs: ^pthread_condattr_t) -> c.int --- pthread_condattr_destroy :: proc(attrs: ^pthread_condattr_t) -> c.int --- @@ -95,7 +94,7 @@ foreign pthread { pthread_mutex_lock :: proc(mutex: ^pthread_mutex_t) -> c.int --- - pthread_mutex_timedlock :: proc(mutex: ^pthread_mutex_t, timeout: ^time.TimeSpec) -> c.int --- + pthread_mutex_timedlock :: proc(mutex: ^pthread_mutex_t, timeout: ^timespec) -> c.int --- pthread_mutex_unlock :: proc(mutex: ^pthread_mutex_t) -> c.int --- diff --git a/core/sys/unix/syscalls_linux.odin b/core/sys/unix/syscalls_linux.odin index 630b4ef24..d611e33f0 100644 --- a/core/sys/unix/syscalls_linux.odin +++ b/core/sys/unix/syscalls_linux.odin @@ -1114,7 +1114,7 @@ when ODIN_ARCH == .amd64 { SYS_landlock_add_rule : uintptr : 445 SYS_landlock_restrict_self : uintptr : 446 SYS_memfd_secret : uintptr : 447 -} else when ODIN_ARCH == .arm { +} else when ODIN_ARCH == .arm32 { // TODO SYS_restart_syscall : uintptr : 0 SYS_exit : uintptr : 1 SYS_fork : uintptr : 2 @@ -1567,7 +1567,7 @@ sys_gettid :: proc "contextless" () -> int { return cast(int)intrinsics.syscall(SYS_gettid) } -sys_getrandom :: proc "contextless" (buf: ^byte, buflen: int, flags: uint) -> int { +sys_getrandom :: proc "contextless" (buf: [^]byte, buflen: int, flags: uint) -> int { return cast(int)intrinsics.syscall(SYS_getrandom, buf, cast(uintptr)(buflen), cast(uintptr)(flags)) } diff --git a/core/sys/unix/time_unix.odin b/core/sys/unix/time_unix.odin new file mode 100644 index 000000000..fa3a7a29d --- /dev/null +++ b/core/sys/unix/time_unix.odin @@ -0,0 +1,75 @@ +//+build linux, darwin, freebsd, openbsd +package unix + +when ODIN_OS == .Darwin { + foreign import libc "System.framework" +} else { + foreign import libc "system:c" +} + +import "core:c" + +@(default_calling_convention="c") +foreign libc { + clock_gettime :: proc(clock_id: u64, timespec: ^timespec) -> c.int --- + sleep :: proc(seconds: c.uint) -> c.int --- + nanosleep :: proc(requested, remaining: ^timespec) -> c.int --- +} + +timespec :: struct { + tv_sec: i64, // seconds + tv_nsec: i64, // nanoseconds +} + +when ODIN_OS == .OpenBSD { + CLOCK_REALTIME :: 0 + CLOCK_PROCESS_CPUTIME_ID :: 2 + CLOCK_MONOTONIC :: 3 + CLOCK_THREAD_CPUTIME_ID :: 4 + CLOCK_UPTIME :: 5 + CLOCK_BOOTTIME :: 6 + + // CLOCK_MONOTONIC_RAW doesn't exist, use CLOCK_MONOTONIC + CLOCK_MONOTONIC_RAW :: CLOCK_MONOTONIC +} else { + CLOCK_REALTIME :: 0 // NOTE(tetra): May jump in time, when user changes the system time. + CLOCK_MONOTONIC :: 1 // NOTE(tetra): May stand still while system is asleep. + CLOCK_PROCESS_CPUTIME_ID :: 2 + CLOCK_THREAD_CPUTIME_ID :: 3 + CLOCK_MONOTONIC_RAW :: 4 // NOTE(tetra): "RAW" means: Not adjusted by NTP. + CLOCK_REALTIME_COARSE :: 5 // NOTE(tetra): "COARSE" clocks are apparently much faster, but not "fine-grained." + CLOCK_MONOTONIC_COARSE :: 6 + CLOCK_BOOTTIME :: 7 // NOTE(tetra): Same as MONOTONIC, except also including time system was asleep. + CLOCK_REALTIME_ALARM :: 8 + CLOCK_BOOTTIME_ALARM :: 9 +} + +// TODO(tetra, 2019-11-05): The original implementation of this package for Darwin used this constants. +// I do not know if Darwin programmers are used to the existance of these constants or not, so +// I'm leaving aliases to them for now. +CLOCK_SYSTEM :: CLOCK_REALTIME +CLOCK_CALENDAR :: CLOCK_MONOTONIC + +boot_time_in_nanoseconds :: proc "c" () -> i64 { + ts_now, ts_boottime: timespec + clock_gettime(CLOCK_REALTIME, &ts_now) + clock_gettime(CLOCK_BOOTTIME, &ts_boottime) + + ns := (ts_now.tv_sec - ts_boottime.tv_sec) * 1e9 + ts_now.tv_nsec - ts_boottime.tv_nsec + return i64(ns) +} + +seconds_since_boot :: proc "c" () -> f64 { + ts_boottime: timespec + clock_gettime(CLOCK_BOOTTIME, &ts_boottime) + return f64(ts_boottime.tv_sec) + f64(ts_boottime.tv_nsec) / 1e9 +} + + +inline_nanosleep :: proc "c" (nanoseconds: i64) -> (remaining: timespec, res: i32) { + s, ns := nanoseconds / 1e9, nanoseconds % 1e9 + requested := timespec{tv_sec=s, tv_nsec=ns} + res = nanosleep(&requested, &remaining) + return +} + diff --git a/core/sys/win32/crt.odin b/core/sys/win32/crt.odin deleted file mode 100644 index b39d35375..000000000 --- a/core/sys/win32/crt.odin +++ /dev/null @@ -1,15 +0,0 @@ -// +build windows -package win32 - -import "core:strings" - -foreign { - @(link_name="_wgetcwd") _get_cwd_wide :: proc(buffer: Wstring, buf_len: int) -> ^Wstring --- -} - -get_cwd :: proc(allocator := context.temp_allocator) -> string { - buffer := make([]u16, MAX_PATH_WIDE, allocator) - _get_cwd_wide(Wstring(&buffer[0]), MAX_PATH_WIDE) - file := utf16_to_utf8(buffer[:], allocator) - return strings.trim_right_null(file) -} diff --git a/core/sys/win32/gdi32.odin b/core/sys/win32/gdi32.odin deleted file mode 100644 index 13bc4796f..000000000 --- a/core/sys/win32/gdi32.odin +++ /dev/null @@ -1,26 +0,0 @@ -// +build windows -package win32 - -foreign import "system:gdi32.lib" - -WHITENESS :: 0x00FF0062 -BLACKNESS :: 0x00000042 - -@(default_calling_convention = "std") -foreign gdi32 { - @(link_name="GetStockObject") get_stock_object :: proc(fn_object: i32) -> Hgdiobj --- - - @(link_name="StretchDIBits") - stretch_dibits :: proc(hdc: Hdc, - x_dst, y_dst, width_dst, height_dst: i32, - x_src, y_src, width_src, header_src: i32, - bits: rawptr, bits_info: ^Bitmap_Info, - usage: u32, - rop: u32) -> i32 --- - - @(link_name="SetPixelFormat") set_pixel_format :: proc(hdc: Hdc, pixel_format: i32, pfd: ^Pixel_Format_Descriptor) -> Bool --- - @(link_name="ChoosePixelFormat") choose_pixel_format :: proc(hdc: Hdc, pfd: ^Pixel_Format_Descriptor) -> i32 --- - @(link_name="SwapBuffers") swap_buffers :: proc(hdc: Hdc) -> Bool --- - - @(link_name="PatBlt") pat_blt :: proc(hdc: Hdc, x, y, w, h: i32, rop: u32) -> Bool --- -} diff --git a/core/sys/win32/general.odin b/core/sys/win32/general.odin deleted file mode 100644 index d53bf8a4f..000000000 --- a/core/sys/win32/general.odin +++ /dev/null @@ -1,1176 +0,0 @@ -// +build windows -package win32 - -Uint_Ptr :: distinct uintptr -Int_Ptr :: distinct int -Long_Ptr :: distinct int - -Handle :: distinct rawptr -Hwnd :: distinct Handle -Hdc :: distinct Handle -Hinstance :: distinct Handle -Hicon :: distinct Handle -Hcursor :: distinct Handle -Hmenu :: distinct Handle -Hbitmap :: distinct Handle -Hbrush :: distinct Handle -Hgdiobj :: distinct Handle -Hmodule :: distinct Handle -Hmonitor :: distinct Handle -Hrawinput :: distinct Handle -Hresult :: distinct i32 -HKL :: distinct Handle -Wparam :: distinct Uint_Ptr -Lparam :: distinct Long_Ptr -Lresult :: distinct Long_Ptr -Wnd_Proc :: distinct #type proc "std" (Hwnd, u32, Wparam, Lparam) -> Lresult -Monitor_Enum_Proc :: distinct #type proc "std" (Hmonitor, Hdc, ^Rect, Lparam) -> bool - - - -Bool :: distinct b32 - -Wstring :: distinct ^u16 - -Point :: struct { - x, y: i32, -} - -Wnd_Class_A :: struct { - style: u32, - wnd_proc: Wnd_Proc, - cls_extra, wnd_extra: i32, - instance: Hinstance, - icon: Hicon, - cursor: Hcursor, - background: Hbrush, - menu_name, class_name: cstring, -} - -Wnd_Class_W :: struct { - style: u32, - wnd_proc: Wnd_Proc, - cls_extra, wnd_extra: i32, - instance: Hinstance, - icon: Hicon, - cursor: Hcursor, - background: Hbrush, - menu_name, class_name: Wstring, -} - -Wnd_Class_Ex_A :: struct { - size, style: u32, - wnd_proc: Wnd_Proc, - cls_extra, wnd_extra: i32, - instance: Hinstance, - icon: Hicon, - cursor: Hcursor, - background: Hbrush, - menu_name, class_name: cstring, - sm: Hicon, -} - -Wnd_Class_Ex_W :: struct { - size, style: u32, - wnd_proc: Wnd_Proc, - cls_extra, wnd_extra: i32, - instance: Hinstance, - icon: Hicon, - cursor: Hcursor, - background: Hbrush, - menu_name, class_name: Wstring, - sm: Hicon, -} - - -Msg :: struct { - hwnd: Hwnd, - message: u32, - wparam: Wparam, - lparam: Lparam, - time: u32, - pt: Point, -} - -Rect :: struct { - left: i32, - top: i32, - right: i32, - bottom: i32, -} - -Dev_Mode_A :: struct { - device_name: [32]u8, - spec_version: u16, - driver_version: u16, - size: u16, - driver_extra: u16, - fields: u32, - using _: struct #raw_union { - // Printer only fields. - using _: struct { - orientation: i16, - paper_size: i16, - paper_length: i16, - paper_width: i16, - scale: i16, - copies: i16, - default_source: i16, - print_quality: i16, - }, - // Display only fields. - using _: struct { - position: Point, - display_orientation: u32, - display_fixed_output: u32, - }, - }, - color: i16, - duplex: i16, - y_resolution: i16, - tt_option: i16, - collate: i16, - form_name: [32]u8, - log_pixels: u16, - bits_per_pel: u32, - pels_width: u32, - pels_height: u32, - using _: struct #raw_union { - display_flags: u32, - nup: u32, - }, - display_frequency: u32, - icm_method: u32, - icm_intent: u32, - media_type: u32, - dither_type: u32, - reserved_1: u32, - reserved_2: u32, - panning_width: u32, - panning_height: u32, -} - -Filetime :: struct { - lo, hi: u32, -} - -Systemtime :: struct { - year, month: u16, - day_of_week, day: u16, - hour, minute, second, millisecond: u16, -} - -By_Handle_File_Information :: struct { - file_attributes: u32, - creation_time, - last_access_time, - last_write_time: Filetime, - volume_serial_number, - file_size_high, - file_size_low, - number_of_links, - file_index_high, - file_index_low: u32, -} - -File_Attribute_Data :: struct { - file_attributes: u32, - creation_time, - last_access_time, - last_write_time: Filetime, - file_size_high, - file_size_low: u32, -} - -// NOTE(Jeroen): The widechar version might want at least the 32k MAX_PATH_WIDE -// https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilew#parameters -Find_Data_W :: struct{ - file_attributes: u32, - creation_time: Filetime, - last_access_time: Filetime, - last_write_time: Filetime, - file_size_high: u32, - file_size_low: u32, - reserved0: u32, - reserved1: u32, - file_name: [MAX_PATH]u16, - alternate_file_name: [14]u16, -} - -Find_Data_A :: struct{ - file_attributes: u32, - creation_time: Filetime, - last_access_time: Filetime, - last_write_time: Filetime, - file_size_high: u32, - file_size_low: u32, - reserved0: u32, - reserved1: u32, - file_name: [MAX_PATH]byte, - alternate_file_name: [14]byte, -} - -Security_Attributes :: struct { - length: u32, - security_descriptor: rawptr, - inherit_handle: Bool, -} - -Process_Information :: struct { - process: Handle, - thread: Handle, - process_id: u32, - thread_id: u32, -} - -Startup_Info :: struct { - cb: u32, - reserved: Wstring, - desktop: Wstring, - title: Wstring, - x: u32, - y: u32, - x_size: u32, - y_size: u32, - x_count_chars: u32, - y_count_chars: u32, - fill_attribute: u32, - flags: u32, - show_window: u16, - _: u16, - _: cstring, - stdin: Handle, - stdout: Handle, - stderr: Handle, -} - -Pixel_Format_Descriptor :: struct { - size, - version, - flags: u32, - - pixel_type, - color_bits, - red_bits, - red_shift, - green_bits, - green_shift, - blue_bits, - blue_shift, - alpha_bits, - alpha_shift, - accum_bits, - accum_red_bits, - accum_green_bits, - accum_blue_bits, - accum_alpha_bits, - depth_bits, - stencil_bits, - aux_buffers, - layer_type, - reserved: byte, - - layer_mask, - visible_mask, - damage_mask: u32, -} - -Critical_Section :: struct { - debug_info: ^Critical_Section_Debug, - - lock_count: i32, - recursion_count: i32, - owning_thread: Handle, - lock_semaphore: Handle, - spin_count: ^u32, -} - -Critical_Section_Debug :: struct { - typ: u16, - creator_back_trace_index: u16, - critical_section: ^Critical_Section, - process_locks_list: ^List_Entry, - entry_count: u32, - contention_count: u32, - flags: u32, - creator_back_trace_index_high: u16, - spare_word: u16, -} - -List_Entry :: struct {flink, blink: ^List_Entry} - - -Raw_Input_Device :: struct { - usage_page: u16, - usage: u16, - flags: u32, - wnd_target: Hwnd, -} - -Raw_Input_Header :: struct { - kind: u32, - size: u32, - device: Handle, - wparam: Wparam, -} - -Raw_HID :: struct { - size_hid: u32, - count: u32, - raw_data: [1]byte, -} - -Raw_Keyboard :: struct { - make_code: u16, - flags: u16, - reserved: u16, - vkey: u16, - message: u32, - extra_information: u32, -} - -Raw_Mouse :: struct { - flags: u16, - using data: struct #raw_union { - buttons: u32, - using _: struct { - button_flags: u16, - button_data: u16, - }, - }, - raw_buttons: u32, - last_x: i32, - last_y: i32, - extra_information: u32, -} - -Raw_Input :: struct { - using header: Raw_Input_Header, - data: struct #raw_union { - mouse: Raw_Mouse, - keyboard: Raw_Keyboard, - hid: Raw_HID, - }, -} - - -Overlapped :: struct { - internal: ^u64, - internal_high: ^u64, - using _: struct #raw_union { - using _: struct { - offset: u32, - offset_high: u32, - }, - pointer: rawptr, - }, - event: Handle, -} - -File_Notify_Information :: struct { - next_entry_offset: u32, - action: u32, - file_name_length: u32, - file_name: [1]u16, -} - -// https://docs.microsoft.com/en-gb/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info -System_Info :: struct { - using _: struct #raw_union { - oem_id: u32, - using _: struct #raw_union { - processor_architecture: u16, - _: u16, // reserved - }, - }, - page_size: u32, - minimum_application_address: rawptr, - maximum_application_address: rawptr, - active_processor_mask: u32, - number_of_processors: u32, - processor_type: u32, - allocation_granularity: u32, - processor_level: u16, - processor_revision: u16, -} - -// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_osversioninfoexa -OS_Version_Info_Ex_A :: struct { - os_version_info_size: u32, - major_version: u32, - minor_version: u32, - build_number: u32, - platform_id : u32, - service_pack_string: [128]u8, - service_pack_major: u16, - service_pack_minor: u16, - suite_mask: u16, - product_type: u8, - reserved: u8, -} - -MAPVK_VK_TO_VSC :: 0 -MAPVK_VSC_TO_VK :: 1 -MAPVK_VK_TO_CHAR :: 2 -MAPVK_VSC_TO_VK_EX :: 3 - -//WinUser.h -ENUM_CURRENT_SETTINGS :: u32(4294967295) // (DWORD)-1 -ENUM_REGISTRY_SETTINGS :: u32(4294967294) // (DWORD)-2 - -VK_LBUTTON :: 0x01 -VK_RBUTTON :: 0x02 -VK_CANCEL :: 0x03 -VK_MBUTTON :: 0x04 /* NOT contiguous with L & RBUTTON */ -VK_XBUTTON1 :: 0x05 /* NOT contiguous with L & RBUTTON */ -VK_XBUTTON2 :: 0x06 /* NOT contiguous with L & RBUTTON */ - -/* - * :: 0x07 : reserved - */ - -VK_BACK :: 0x08 -VK_TAB :: 0x09 - -/* - * :: 0x0A - :: 0x0B : reserved - */ - -VK_CLEAR :: 0x0C -VK_RETURN :: 0x0D - -/* - * :: 0x0E - :: 0x0F : unassigned - */ - -VK_SHIFT :: 0x10 -VK_CONTROL :: 0x11 -VK_MENU :: 0x12 -VK_PAUSE :: 0x13 -VK_CAPITAL :: 0x14 - -VK_KANA :: 0x15 -VK_HANGEUL :: 0x15 /* old name - should be here for compatibility */ -VK_HANGUL :: 0x15 - -/* - * :: 0x16 : unassigned - */ - -VK_JUNJA :: 0x17 -VK_FINAL :: 0x18 -VK_HANJA :: 0x19 -VK_KANJI :: 0x19 - -/* - * :: 0x1A : unassigned - */ - -VK_ESCAPE :: 0x1B - -VK_CONVERT :: 0x1C -VK_NONCONVERT :: 0x1D -VK_ACCEPT :: 0x1E -VK_MODECHANGE :: 0x1F - -VK_SPACE :: 0x20 -VK_PRIOR :: 0x21 -VK_NEXT :: 0x22 -VK_END :: 0x23 -VK_HOME :: 0x24 -VK_LEFT :: 0x25 -VK_UP :: 0x26 -VK_RIGHT :: 0x27 -VK_DOWN :: 0x28 -VK_SELECT :: 0x29 -VK_PRINT :: 0x2A -VK_EXECUTE :: 0x2B -VK_SNAPSHOT :: 0x2C -VK_INSERT :: 0x2D -VK_DELETE :: 0x2E -VK_HELP :: 0x2F - -/* - * VK_0 - VK_9 are the same as ASCII '0' - '9' (:: 0x30 - :: 0x39) - * :: 0x3A - :: 0x40 : unassigned - * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (:: 0x41 - :: 0x5A) - */ - -VK_LWIN :: 0x5B -VK_RWIN :: 0x5C -VK_APPS :: 0x5D - -/* - * :: 0x5E : reserved - */ - -VK_SLEEP :: 0x5F - -VK_NUMPAD0 :: 0x60 -VK_NUMPAD1 :: 0x61 -VK_NUMPAD2 :: 0x62 -VK_NUMPAD3 :: 0x63 -VK_NUMPAD4 :: 0x64 -VK_NUMPAD5 :: 0x65 -VK_NUMPAD6 :: 0x66 -VK_NUMPAD7 :: 0x67 -VK_NUMPAD8 :: 0x68 -VK_NUMPAD9 :: 0x69 -VK_MULTIPLY :: 0x6A -VK_ADD :: 0x6B -VK_SEPARATOR :: 0x6C -VK_SUBTRACT :: 0x6D -VK_DECIMAL :: 0x6E -VK_DIVIDE :: 0x6F -VK_F1 :: 0x70 -VK_F2 :: 0x71 -VK_F3 :: 0x72 -VK_F4 :: 0x73 -VK_F5 :: 0x74 -VK_F6 :: 0x75 -VK_F7 :: 0x76 -VK_F8 :: 0x77 -VK_F9 :: 0x78 -VK_F10 :: 0x79 -VK_F11 :: 0x7A -VK_F12 :: 0x7B -VK_F13 :: 0x7C -VK_F14 :: 0x7D -VK_F15 :: 0x7E -VK_F16 :: 0x7F -VK_F17 :: 0x80 -VK_F18 :: 0x81 -VK_F19 :: 0x82 -VK_F20 :: 0x83 -VK_F21 :: 0x84 -VK_F22 :: 0x85 -VK_F23 :: 0x86 -VK_F24 :: 0x87 - -INVALID_HANDLE :: Handle(~uintptr(0)) - -CREATE_SUSPENDED :: 0x00000004 -STACK_SIZE_PARAM_IS_A_RESERVATION :: 0x00010000 -WAIT_ABANDONED :: 0x00000080 -WAIT_OBJECT_0 :: 0 -WAIT_TIMEOUT :: 0x00000102 -WAIT_FAILED :: 0xffffffff - -CS_VREDRAW :: 0x0001 -CS_HREDRAW :: 0x0002 -CS_OWNDC :: 0x0020 -CW_USEDEFAULT :: -0x80000000 - -WS_OVERLAPPED :: 0 -WS_MAXIMIZEBOX :: 0x00010000 -WS_MINIMIZEBOX :: 0x00020000 -WS_THICKFRAME :: 0x00040000 -WS_SYSMENU :: 0x00080000 -WS_BORDER :: 0x00800000 -WS_CAPTION :: 0x00C00000 -WS_VISIBLE :: 0x10000000 -WS_POPUP :: 0x80000000 -WS_MAXIMIZE :: 0x01000000 -WS_MINIMIZE :: 0x20000000 -WS_OVERLAPPEDWINDOW :: WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX -WS_POPUPWINDOW :: WS_POPUP | WS_BORDER | WS_SYSMENU - -WS_EX_DLGMODALFRAME :: 0x00000001 -WS_EX_NOPARENTNOTIFY :: 0x00000004 -WS_EX_TOPMOST :: 0x00000008 -WS_EX_ACCEPTFILES :: 0x00000010 -WS_EX_TRANSPARENT :: 0x00000020 -WS_EX_MDICHILD :: 0x00000040 -WS_EX_TOOLWINDOW :: 0x00000080 -WS_EX_WINDOWEDGE :: 0x00000100 -WS_EX_CLIENTEDGE :: 0x00000200 -WS_EX_CONTEXTHELP :: 0x00000400 -WS_EX_RIGHT :: 0x00001000 -WS_EX_LEFT :: 0x00000000 -WS_EX_RTLREADING :: 0x00002000 -WS_EX_LTRREADING :: 0x00000000 -WS_EX_LEFTSCROLLBAR :: 0x00004000 -WS_EX_RIGHTSCROLLBAR :: 0x00000000 -WS_EX_CONTROLPARENT :: 0x00010000 -WS_EX_STATICEDGE :: 0x00020000 -WS_EX_APPWINDOW :: 0x00040000 -WS_EX_OVERLAPPEDWINDOW :: WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE -WS_EX_PALETTEWINDOW :: WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST -WS_EX_LAYERED :: 0x00080000 -WS_EX_NOINHERITLAYOUT :: 0x00100000 // Disable inheritence of mirroring by children -WS_EX_NOREDIRECTIONBITMAP :: 0x00200000 -WS_EX_LAYOUTRTL :: 0x00400000 // Right to left mirroring -WS_EX_COMPOSITED :: 0x02000000 -WS_EX_NOACTIVATE :: 0x08000000 - -WM_ACTIVATE :: 0x0006 -WM_ACTIVATEAPP :: 0x001C -WM_CHAR :: 0x0102 -WM_CLOSE :: 0x0010 -WM_CREATE :: 0x0001 -WM_DESTROY :: 0x0002 -WM_INPUT :: 0x00FF -WM_KEYDOWN :: 0x0100 -WM_KEYUP :: 0x0101 -WM_KILLFOCUS :: 0x0008 -WM_QUIT :: 0x0012 -WM_SETCURSOR :: 0x0020 -WM_SETFOCUS :: 0x0007 -WM_SIZE :: 0x0005 -WM_SIZING :: 0x0214 -WM_SYSKEYDOWN :: 0x0104 -WM_SYSKEYUP :: 0x0105 -WM_USER :: 0x0400 -WM_WINDOWPOSCHANGED :: 0x0047 -WM_COMMAND :: 0x0111 -WM_PAINT :: 0x000F - -WM_MOUSEWHEEL :: 0x020A -WM_MOUSEMOVE :: 0x0200 -WM_LBUTTONDOWN :: 0x0201 -WM_LBUTTONUP :: 0x0202 -WM_LBUTTONDBLCLK :: 0x0203 -WM_RBUTTONDOWN :: 0x0204 -WM_RBUTTONUP :: 0x0205 -WM_RBUTTONDBLCLK :: 0x0206 -WM_MBUTTONDOWN :: 0x0207 -WM_MBUTTONUP :: 0x0208 -WM_MBUTTONDBLCLK :: 0x0209 - -PM_NOREMOVE :: 0x0000 -PM_REMOVE :: 0x0001 -PM_NOYIELD :: 0x0002 - -BLACK_BRUSH :: 4 - -SM_CXSCREEN :: 0 -SM_CYSCREEN :: 1 - -SW_SHOW :: 5 - -COLOR_BACKGROUND :: Hbrush(uintptr(1)) - -INVALID_SET_FILE_POINTER :: ~u32(0) -HEAP_ZERO_MEMORY :: 0x00000008 -INFINITE :: 0xffffffff -GWL_EXSTYLE :: -20 -GWLP_HINSTANCE :: -6 -GWLP_ID :: -12 -GWL_STYLE :: -16 -GWLP_USERDATA :: -21 -GWLP_WNDPROC :: -4 -Hwnd_TOP :: Hwnd(uintptr(0)) - -BI_RGB :: 0 -DIB_RGB_COLORS :: 0x00 -SRCCOPY: u32 : 0x00cc0020 - - -MONITOR_DEFAULTTONULL :: 0x00000000 -MONITOR_DEFAULTTOPRIMARY :: 0x00000001 -MONITOR_DEFAULTTONEAREST :: 0x00000002 - -SWP_FRAMECHANGED :: 0x0020 -SWP_NOOWNERZORDER :: 0x0200 -SWP_NOZORDER :: 0x0004 -SWP_NOSIZE :: 0x0001 -SWP_NOMOVE :: 0x0002 - - -// Raw Input - - -RID_HEADER :: 0x10000005 -RID_INPUT :: 0x10000003 - - -RIDEV_APPKEYS :: 0x00000400 -RIDEV_CAPTUREMOUSE :: 0x00000200 -RIDEV_DEVNOTIFY :: 0x00002000 -RIDEV_EXCLUDE :: 0x00000010 -RIDEV_EXINPUTSINK :: 0x00001000 -RIDEV_INPUTSINK :: 0x00000100 -RIDEV_NOHOTKEYS :: 0x00000200 -RIDEV_NOLEGACY :: 0x00000030 -RIDEV_PAGEONLY :: 0x00000020 -RIDEV_REMOVE :: 0x00000001 - - -RIM_TYPEMOUSE :: 0 -RIM_TYPEKEYBOARD :: 1 -RIM_TYPEHID :: 2 - - -MOUSE_ATTRIBUTES_CHANGED :: 0x04 -MOUSE_MOVE_RELATIVE :: 0 -MOUSE_MOVE_ABSOLUTE :: 1 -MOUSE_VIRTUAL_DESKTOP :: 0x02 - - - -RI_MOUSE_BUTTON_1_DOWN :: 0x0001 -RI_MOUSE_BUTTON_1_UP :: 0x0002 -RI_MOUSE_BUTTON_2_DOWN :: 0x0004 -RI_MOUSE_BUTTON_2_UP :: 0x0008 -RI_MOUSE_BUTTON_3_DOWN :: 0x0010 -RI_MOUSE_BUTTON_3_UP :: 0x0020 -RI_MOUSE_BUTTON_4_DOWN :: 0x0040 -RI_MOUSE_BUTTON_4_UP :: 0x0080 -RI_MOUSE_BUTTON_5_DOWN :: 0x0100 -RI_MOUSE_BUTTON_5_UP :: 0x0200 -RI_MOUSE_LEFT_BUTTON_DOWN :: 0x0001 -RI_MOUSE_LEFT_BUTTON_UP :: 0x0002 -RI_MOUSE_MIDDLE_BUTTON_DOWN :: 0x0010 -RI_MOUSE_MIDDLE_BUTTON_UP :: 0x0020 -RI_MOUSE_RIGHT_BUTTON_DOWN :: 0x0004 -RI_MOUSE_RIGHT_BUTTON_UP :: 0x0008 -RI_MOUSE_WHEEL :: 0x0400 - - -RI_KEY_MAKE :: 0x00 -RI_KEY_BREAK :: 0x01 -RI_KEY_E0 :: 0x02 -RI_KEY_E1 :: 0x04 -RI_KEY_TERMSRV_SET_LED :: 0x08 -RI_KEY_TERMSRV_SHADOW :: 0x10 - -// Windows OpenGL - -PFD_TYPE_RGBA :: 0 -PFD_TYPE_COLORINDEX :: 1 -PFD_MAIN_PLANE :: 0 -PFD_OVERLAY_PLANE :: 1 -PFD_UNDERLAY_PLANE :: -1 -PFD_DOUBLEBUFFER :: 1 -PFD_STEREO :: 2 -PFD_DRAW_TO_WINDOW :: 4 -PFD_DRAW_TO_BITMAP :: 8 -PFD_SUPPORT_GDI :: 16 -PFD_SUPPORT_OPENGL :: 32 -PFD_GENERIC_FORMAT :: 64 -PFD_NEED_PALETTE :: 128 -PFD_NEED_SYSTEM_PALETTE :: 0x00000100 -PFD_SWAP_EXCHANGE :: 0x00000200 -PFD_SWAP_COPY :: 0x00000400 -PFD_SWAP_LAYER_BUFFERS :: 0x00000800 -PFD_GENERIC_ACCELERATED :: 0x00001000 -PFD_DEPTH_DONTCARE :: 0x20000000 -PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000 -PFD_STEREO_DONTCARE :: 0x80000000 - -GET_FILEEX_INFO_LEVELS :: distinct i32 -GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS : 0 -GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS : 1 - -STARTF_USESHOWWINDOW :: 0x00000001 -STARTF_USESIZE :: 0x00000002 -STARTF_USEPOSITION :: 0x00000004 -STARTF_USECOUNTCHARS :: 0x00000008 -STARTF_USEFILLATTRIBUTE :: 0x00000010 -STARTF_RUNFULLSCREEN :: 0x00000020 // ignored for non-x86 platforms -STARTF_FORCEONFEEDBACK :: 0x00000040 -STARTF_FORCEOFFFEEDBACK :: 0x00000080 -STARTF_USESTDHANDLES :: 0x00000100 -STARTF_USEHOTKEY :: 0x00000200 -STARTF_TITLEISLINKNAME :: 0x00000800 -STARTF_TITLEISAPPID :: 0x00001000 -STARTF_PREVENTPINNING :: 0x00002000 -STARTF_UNTRUSTEDSOURCE :: 0x00008000 - - -MOVEFILE_REPLACE_EXISTING :: 0x00000001 -MOVEFILE_COPY_ALLOWED :: 0x00000002 -MOVEFILE_DELAY_UNTIL_REBOOT :: 0x00000004 -MOVEFILE_WRITE_THROUGH :: 0x00000008 -MOVEFILE_CREATE_HARDLINK :: 0x00000010 -MOVEFILE_FAIL_IF_NOT_TRACKABLE :: 0x00000020 - -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 - -FILE_FLAG_WRITE_THROUGH :: 0x80000000 -FILE_FLAG_OVERLAPPED :: 0x40000000 -FILE_FLAG_NO_BUFFERING :: 0x20000000 -FILE_FLAG_RANDOM_ACCESS :: 0x10000000 -FILE_FLAG_SEQUENTIAL_SCAN :: 0x08000000 -FILE_FLAG_DELETE_ON_CLOSE :: 0x04000000 -FILE_FLAG_BACKUP_SEMANTICS :: 0x02000000 -FILE_FLAG_POSIX_SEMANTICS :: 0x01000000 -FILE_FLAG_SESSION_AWARE :: 0x00800000 -FILE_FLAG_OPEN_REPARSE_POINT :: 0x00200000 -FILE_FLAG_OPEN_NO_RECALL :: 0x00100000 -FILE_FLAG_FIRST_PIPE_INSTANCE :: 0x00080000 - -FILE_ACTION_ADDED :: 0x00000001 -FILE_ACTION_REMOVED :: 0x00000002 -FILE_ACTION_MODIFIED :: 0x00000003 -FILE_ACTION_RENAMED_OLD_NAME :: 0x00000004 -FILE_ACTION_RENAMED_NEW_NAME :: 0x00000005 - -CP_ACP :: 0 // default to ANSI code page -CP_OEMCP :: 1 // default to OEM code page -CP_MACCP :: 2 // default to MAC code page -CP_THREAD_ACP :: 3 // current thread's ANSI code page -CP_SYMBOL :: 42 // SYMBOL translations -CP_UTF7 :: 65000 // UTF-7 translation -CP_UTF8 :: 65001 // UTF-8 translation - - -MB_ERR_INVALID_CHARS :: 8 -WC_ERR_INVALID_CHARS :: 128 - -utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 { - if len(s) < 1 { - return nil - } - - b := transmute([]byte)s - cstr := cstring(&b[0]) - n := multi_byte_to_wide_char(CP_UTF8, MB_ERR_INVALID_CHARS, cstr, i32(len(s)), nil, 0) - if n == 0 { - return nil - } - - text := make([]u16, n+1, allocator) - - n1 := multi_byte_to_wide_char(CP_UTF8, MB_ERR_INVALID_CHARS, cstr, i32(len(s)), Wstring(&text[0]), i32(n)) - if n1 == 0 { - delete(text, allocator) - return nil - } - - text[n] = 0 - for n >= 1 && text[n-1] == 0 { - n -= 1 - } - return text[:n] -} -utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> Wstring { - if res := utf8_to_utf16(s, allocator); res != nil { - return Wstring(&res[0]) - } - return nil -} - -wstring_to_utf8 :: proc(s: Wstring, N: int, allocator := context.temp_allocator) -> string { - if N == 0 { - return "" - } - - n := wide_char_to_multi_byte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), nil, 0, nil, nil) - if n == 0 { - return "" - } - - // If N == -1 the call to wide_char_to_multi_byte assume the wide string is null terminated - // and will scan it to find the first null terminated character. The resulting string will - // 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, allocator) - - if n1 := wide_char_to_multi_byte(CP_UTF8, WC_ERR_INVALID_CHARS, s, i32(N), cstring(&text[0]), n, nil, nil); n1 == 0 { - delete(text, allocator) - return "" - } - - for i in 0..<n { - if text[i] == 0 { - n = i - break - } - } - - return string(text[:n]) -} - -utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string { - if len(s) == 0 { - return "" - } - return wstring_to_utf8(cast(Wstring)&s[0], len(s), allocator) -} - -get_query_performance_frequency :: proc() -> i64 { - r: i64 - query_performance_frequency(&r) - return r -} - -HIWORD_W :: proc(wParam: Wparam) -> u16 { return u16((u32(wParam) >> 16) & 0xffff) } -HIWORD_L :: proc(lParam: Lparam) -> u16 { return u16((u32(lParam) >> 16) & 0xffff) } -LOWORD_W :: proc(wParam: Wparam) -> u16 { return u16(wParam) } -LOWORD_L :: proc(lParam: Lparam) -> u16 { return u16(lParam) } - -is_key_down :: #force_inline proc(key: Key_Code) -> bool { return get_async_key_state(i32(key)) < 0 } - - - - -MAX_PATH :: 0x00000104 -MAX_PATH_WIDE :: 0x8000 - -HANDLE_FLAG_INHERIT :: 1 -HANDLE_FLAG_PROTECT_FROM_CLOSE :: 2 - -FILE_BEGIN :: 0 -FILE_CURRENT :: 1 -FILE_END :: 2 - -FILE_SHARE_READ :: 0x00000001 -FILE_SHARE_WRITE :: 0x00000002 -FILE_SHARE_DELETE :: 0x00000004 -FILE_GENERIC_ALL :: 0x10000000 -FILE_GENERIC_EXECUTE :: 0x20000000 -FILE_GENERIC_WRITE :: 0x40000000 -FILE_GENERIC_READ :: 0x80000000 - -FILE_READ_DATA :: 0x0001 -FILE_LIST_DIRECTORY :: 0x0001 -FILE_WRITE_DATA :: 0x0002 -FILE_ADD_FILE :: 0x0002 -FILE_APPEND_DATA :: 0x0004 -FILE_ADD_SUBDIRECTORY :: 0x0004 -FILE_CREATE_PIPE_INSTANCE :: 0x0004 -FILE_READ_EA :: 0x0008 -FILE_WRITE_EA :: 0x0010 -FILE_EXECUTE :: 0x0020 -FILE_TRAVERSE :: 0x0020 -FILE_DELETE_CHILD :: 0x0040 -FILE_READ_ATTRIBUTES :: 0x0080 -FILE_WRITE_ATTRIBUTES :: 0x0100 - -STD_INPUT_HANDLE :: -10 -STD_OUTPUT_HANDLE :: -11 -STD_ERROR_HANDLE :: -12 - -CREATE_NEW :: 1 -CREATE_ALWAYS :: 2 -OPEN_EXISTING :: 3 -OPEN_ALWAYS :: 4 -TRUNCATE_EXISTING :: 5 - -INVALID_FILE_ATTRIBUTES :: -1 - -FILE_ATTRIBUTE_READONLY :: 0x00000001 -FILE_ATTRIBUTE_HIDDEN :: 0x00000002 -FILE_ATTRIBUTE_SYSTEM :: 0x00000004 -FILE_ATTRIBUTE_DIRECTORY :: 0x00000010 -FILE_ATTRIBUTE_ARCHIVE :: 0x00000020 -FILE_ATTRIBUTE_DEVICE :: 0x00000040 -FILE_ATTRIBUTE_NORMAL :: 0x00000080 -FILE_ATTRIBUTE_TEMPORARY :: 0x00000100 -FILE_ATTRIBUTE_SPARSE_FILE :: 0x00000200 -FILE_ATTRIBUTE_REPARSE_Point :: 0x00000400 -FILE_ATTRIBUTE_COMPRESSED :: 0x00000800 -FILE_ATTRIBUTE_OFFLINE :: 0x00001000 -FILE_ATTRIBUTE_NOT_CONTENT_INDEXED :: 0x00002000 -FILE_ATTRIBUTE_ENCRYPTED :: 0x00004000 - -FILE_TYPE_DISK :: 0x0001 -FILE_TYPE_CHAR :: 0x0002 -FILE_TYPE_PIPE :: 0x0003 - - -Monitor_Info :: struct { - size: u32, - monitor: Rect, - work: Rect, - flags: u32, -} - -Window_Placement :: struct { - length: u32, - flags: u32, - show_cmd: u32, - min_pos: Point, - max_pos: Point, - normal_pos: Rect, -} - -Bitmap_Info_Header :: struct { - size: u32, - width, height: i32, - planes, bit_count: i16, - compression: u32, - size_image: u32, - x_pels_per_meter: i32, - y_pels_per_meter: i32, - clr_used: u32, - clr_important: u32, -} -Bitmap_Info :: struct { - using header: Bitmap_Info_Header, - colors: [1]Rgb_Quad, -} - -Paint_Struct :: struct { - hdc: Hdc, - erase: Bool, - rc_paint: Rect, - restore: Bool, - inc_update: Bool, - rgb_reserved: [32]byte, -} - - -Rgb_Quad :: struct {blue, green, red, reserved: byte} - - -Key_Code :: enum i32 { - Unknown = 0x00, - - Lbutton = 0x01, - Rbutton = 0x02, - Cancel = 0x03, - Mbutton = 0x04, - Xbutton1 = 0x05, - Xbutton2 = 0x06, - Back = 0x08, - Tab = 0x09, - Clear = 0x0C, - Return = 0x0D, - - Shift = 0x10, - Control = 0x11, - Menu = 0x12, - Pause = 0x13, - Capital = 0x14, - Kana = 0x15, - Hangeul = 0x15, - Hangul = 0x15, - Junja = 0x17, - Final = 0x18, - Hanja = 0x19, - Kanji = 0x19, - Escape = 0x1B, - Convert = 0x1C, - NonConvert = 0x1D, - Accept = 0x1E, - ModeChange = 0x1F, - Space = 0x20, - Prior = 0x21, - Next = 0x22, - End = 0x23, - Home = 0x24, - Left = 0x25, - Up = 0x26, - Right = 0x27, - Down = 0x28, - Select = 0x29, - Print = 0x2A, - Execute = 0x2B, - Snapshot = 0x2C, - Insert = 0x2D, - Delete = 0x2E, - Help = 0x2F, - - Num0 = '0', - Num1 = '1', - Num2 = '2', - Num3 = '3', - Num4 = '4', - Num5 = '5', - Num6 = '6', - Num7 = '7', - Num8 = '8', - Num9 = '9', - A = 'A', - B = 'B', - C = 'C', - D = 'D', - E = 'E', - F = 'F', - G = 'G', - H = 'H', - I = 'I', - J = 'J', - K = 'K', - L = 'L', - M = 'M', - N = 'N', - O = 'O', - P = 'P', - Q = 'Q', - R = 'R', - S = 'S', - T = 'T', - U = 'U', - V = 'V', - W = 'W', - X = 'X', - Y = 'Y', - Z = 'Z', - - Lwin = 0x5B, - Rwin = 0x5C, - Apps = 0x5D, - - Numpad0 = 0x60, - Numpad1 = 0x61, - Numpad2 = 0x62, - Numpad3 = 0x63, - Numpad4 = 0x64, - Numpad5 = 0x65, - Numpad6 = 0x66, - Numpad7 = 0x67, - Numpad8 = 0x68, - Numpad9 = 0x69, - Multiply = 0x6A, - Add = 0x6B, - Separator = 0x6C, - Subtract = 0x6D, - Decimal = 0x6E, - Divide = 0x6F, - - F1 = 0x70, - F2 = 0x71, - F3 = 0x72, - F4 = 0x73, - F5 = 0x74, - F6 = 0x75, - F7 = 0x76, - F8 = 0x77, - F9 = 0x78, - F10 = 0x79, - F11 = 0x7A, - F12 = 0x7B, - F13 = 0x7C, - F14 = 0x7D, - F15 = 0x7E, - F16 = 0x7F, - F17 = 0x80, - F18 = 0x81, - F19 = 0x82, - F20 = 0x83, - F21 = 0x84, - F22 = 0x85, - F23 = 0x86, - F24 = 0x87, - - Numlock = 0x90, - Scroll = 0x91, - Lshift = 0xA0, - Rshift = 0xA1, - Lcontrol = 0xA2, - Rcontrol = 0xA3, - Lmenu = 0xA4, - Rmenu = 0xA5, - ProcessKey = 0xE5, - Attn = 0xF6, - Crsel = 0xF7, - Exsel = 0xF8, - Ereof = 0xF9, - Play = 0xFA, - Zoom = 0xFB, - Noname = 0xFC, - Pa1 = 0xFD, - OemClear = 0xFE, -} - diff --git a/core/sys/win32/helpers.odin b/core/sys/win32/helpers.odin deleted file mode 100644 index b04e5db95..000000000 --- a/core/sys/win32/helpers.odin +++ /dev/null @@ -1,29 +0,0 @@ -// +build windows -package win32 - -import "core:strings" - -call_external_process :: proc(program, command_line: string) -> bool { - si := Startup_Info{ cb=size_of(Startup_Info) } - pi := Process_Information{} - - return cast(bool)create_process_w( - utf8_to_wstring(program), - utf8_to_wstring(command_line), - nil, - nil, - Bool(false), - u32(0x10), - nil, - nil, - &si, - &pi, - ) -} - -open_website :: proc(url: string) -> bool { - p :: "C:\\Windows\\System32\\cmd.exe" - arg := []string{"/C", "start", url} - args := strings.join(arg, " ", context.temp_allocator) - return call_external_process(p, args) -} diff --git a/core/sys/win32/kernel32.odin b/core/sys/win32/kernel32.odin deleted file mode 100644 index 709964fb4..000000000 --- a/core/sys/win32/kernel32.odin +++ /dev/null @@ -1,237 +0,0 @@ -// +build windows -package win32 - -foreign import "system:kernel32.lib" - -@(default_calling_convention = "std") -foreign kernel32 { - @(link_name="CreateProcessA") create_process_a :: proc(application_name, command_line: cstring, - process_attributes, thread_attributes: ^Security_Attributes, - inherit_handle: Bool, creation_flags: u32, environment: rawptr, - current_directory: cstring, startup_info: ^Startup_Info, - process_information: ^Process_Information) -> Bool --- - @(link_name="CreateProcessW") create_process_w :: proc(application_name, command_line: Wstring, - process_attributes, thread_attributes: ^Security_Attributes, - inherit_handle: Bool, creation_flags: u32, environment: rawptr, - current_directory: Wstring, startup_info: ^Startup_Info, - process_information: ^Process_Information) -> Bool --- - @(link_name="GetExitCodeProcess") get_exit_code_process :: proc(process: Handle, exit: ^u32) -> Bool --- - @(link_name="ExitProcess") exit_process :: proc(exit_code: u32) --- - @(link_name="GetModuleHandleA") get_module_handle_a :: proc(module_name: cstring) -> Hmodule --- - @(link_name="GetModuleHandleW") get_module_handle_w :: proc(module_name: Wstring) -> Hmodule --- - - @(link_name="GetModuleFileNameA") get_module_file_name_a :: proc(module: Hmodule, filename: cstring, size: u32) -> u32 --- - @(link_name="GetModuleFileNameW") get_module_file_name_w :: proc(module: Hmodule, filename: Wstring, size: u32) -> u32 --- - - @(link_name="Sleep") sleep :: proc(ms: u32) --- - @(link_name="QueryPerformanceFrequency") query_performance_frequency :: proc(result: ^i64) -> i32 --- - @(link_name="QueryPerformanceCounter") query_performance_counter :: proc(result: ^i64) -> i32 --- - @(link_name="OutputDebugStringA") output_debug_string_a :: proc(c_str: cstring) --- - - @(link_name="GetCommandLineA") get_command_line_a :: proc() -> cstring --- - @(link_name="GetCommandLineW") get_command_line_w :: proc() -> Wstring --- - @(link_name="GetSystemMetrics") get_system_metrics :: proc(index: i32) -> i32 --- - @(link_name="GetSystemInfo") get_system_info :: proc(info: ^System_Info) --- - @(link_name="GetVersionExA") get_version :: proc(osvi: ^OS_Version_Info_Ex_A) --- - @(link_name="GetCurrentThreadId") get_current_thread_id :: proc() -> u32 --- - - // NOTE(tetra): Not thread safe with SetCurrentDirectory and GetFullPathName; - // The current directory is stored as a global variable in the process. - @(link_name="GetCurrentDirectoryW") get_current_directory_w :: proc(len: u32, buf: Wstring) -> u32 --- - @(link_name="SetCurrentDirectoryW") set_current_directory_w :: proc(buf: Wstring) -> u32 --- - - @(link_name="GetSystemTimeAsFileTime") get_system_time_as_file_time :: proc(system_time_as_file_time: ^Filetime) --- - @(link_name="FileTimeToLocalFileTime") file_time_to_local_file_time :: proc(file_time: ^Filetime, local_file_time: ^Filetime) -> Bool --- - @(link_name="FileTimeToSystemTime") file_time_to_system_time :: proc(file_time: ^Filetime, system_time: ^Systemtime) -> Bool --- - @(link_name="SystemTimeToFileTime") system_time_to_file_time :: proc(system_time: ^Systemtime, file_time: ^Filetime) -> Bool --- - - @(link_name="GetStdHandle") get_std_handle :: proc(h: i32) -> Handle --- - - @(link_name="CreateFileA") - create_file_a :: proc(filename: cstring, desired_access, share_module: u32, - security: rawptr, - creation, flags_and_attribs: u32, template_file: Handle) -> Handle --- - - @(link_name="CreateFileW") - create_file_w :: proc(filename: Wstring, desired_access, share_module: u32, - security: rawptr, - creation, flags_and_attribs: u32, template_file: Handle) -> Handle --- - - - @(link_name="ReadFile") read_file :: proc(h: Handle, buf: rawptr, to_read: u32, bytes_read: ^i32, overlapped: rawptr) -> Bool --- - @(link_name="WriteFile") write_file :: proc(h: Handle, buf: rawptr, len: i32, written_result: ^i32, overlapped: rawptr) -> Bool --- - - @(link_name="GetFileSizeEx") get_file_size_ex :: proc(file_handle: Handle, file_size: ^i64) -> Bool --- - @(link_name="GetFileInformationByHandle") get_file_information_by_handle :: proc(file_handle: Handle, file_info: ^By_Handle_File_Information) -> Bool --- - - @(link_name="CreateDirectoryA") create_directory_a :: proc(path: cstring, security_attributes: ^Security_Attributes) -> Bool --- - @(link_name="CreateDirectoryW") create_directory_w :: proc(path: Wstring, security_attributes: ^Security_Attributes) -> Bool --- - - @(link_name="GetFileType") get_file_type :: proc(file_handle: Handle) -> u32 --- - @(link_name="SetFilePointer") set_file_pointer :: proc(file_handle: Handle, distance_to_move: i32, distance_to_move_high: ^i32, move_method: u32) -> u32 --- - - @(link_name="SetHandleInformation") set_handle_information :: proc(obj: Handle, mask, flags: u32) -> Bool --- - - @(link_name="FindFirstFileA") find_first_file_a :: proc(file_name: cstring, data: ^Find_Data_A) -> Handle --- - @(link_name="FindNextFileA") find_next_file_a :: proc(file: Handle, data: ^Find_Data_A) -> Bool --- - - @(link_name="FindFirstFileW") find_first_file_w :: proc(file_name: Wstring, data: ^Find_Data_W) -> Handle --- - @(link_name="FindNextFileW") find_next_file_w :: proc(file: Handle, data: ^Find_Data_W) -> Bool --- - - @(link_name="FindClose") find_close :: proc(file: Handle) -> Bool --- - - @(link_name="MoveFileExA") move_file_ex_a :: proc(existing, new: cstring, flags: u32) -> Bool --- - @(link_name="DeleteFileA") delete_file_a :: proc(file_name: cstring) -> Bool --- - @(link_name="CopyFileA") copy_file_a :: proc(existing, new: cstring, fail_if_exists: Bool) -> Bool --- - - @(link_name="MoveFileExW") move_file_ex_w :: proc(existing, new: Wstring, flags: u32) -> Bool --- - @(link_name="DeleteFileW") delete_file_w :: proc(file_name: Wstring) -> Bool --- - @(link_name="CopyFileW") copy_file_w :: proc(existing, new: Wstring, fail_if_exists: Bool) -> Bool --- - - @(link_name="HeapAlloc") heap_alloc :: proc(h: Handle, flags: u32, bytes: int) -> rawptr --- - @(link_name="HeapReAlloc") heap_realloc :: proc(h: Handle, flags: u32, memory: rawptr, bytes: int) -> rawptr --- - @(link_name="HeapFree") heap_free :: proc(h: Handle, flags: u32, memory: rawptr) -> Bool --- - @(link_name="GetProcessHeap") get_process_heap :: proc() -> Handle --- - - @(link_name="LocalAlloc") local_alloc :: proc(flags: u32, bytes: int) -> rawptr --- - @(link_name="LocalReAlloc") local_realloc :: proc(mem: rawptr, bytes: int, flags: uint) -> rawptr --- - @(link_name="LocalFree") local_free :: proc(mem: rawptr) -> rawptr --- - - @(link_name="FindFirstChangeNotificationA") find_first_change_notification_a :: proc(path: cstring, watch_subtree: Bool, filter: u32) -> Handle --- - @(link_name="FindNextChangeNotification") find_next_change_notification :: proc(h: Handle) -> Bool --- - @(link_name="FindCloseChangeNotification") find_close_change_notification :: proc(h: Handle) -> Bool --- - - @(link_name="ReadDirectoryChangesW") read_directory_changes_w :: proc(dir: Handle, buf: rawptr, buf_length: u32, - watch_subtree: Bool, notify_filter: u32, - bytes_returned: ^u32, overlapped: ^Overlapped, - completion: rawptr) -> Bool --- - - @(link_name="GetOverlappedResult") get_overlapped_result :: proc(file: Handle, overlapped: ^Overlapped, number_of_bytes_transferred: ^u32, wait: Bool) -> Bool --- - - @(link_name="WideCharToMultiByte") wide_char_to_multi_byte :: proc(code_page: u32, flags: u32, - wchar_str: Wstring, wchar: i32, - multi_str: cstring, multi: i32, - default_char: cstring, used_default_char: ^Bool) -> i32 --- - - @(link_name="MultiByteToWideChar") multi_byte_to_wide_char :: proc(code_page: u32, flags: u32, - mb_str: cstring, mb: i32, - wc_str: Wstring, wc: i32) -> i32 --- - - @(link_name="CreateSemaphoreA") create_semaphore_a :: proc(attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: cstring) -> Handle --- - @(link_name="CreateSemaphoreW") create_semaphore_w :: proc(attributes: ^Security_Attributes, initial_count, maximum_count: i32, name: cstring) -> Handle --- - @(link_name="ReleaseSemaphore") release_semaphore :: proc(semaphore: Handle, release_count: i32, previous_count: ^i32) -> Bool --- - @(link_name="WaitForSingleObject") wait_for_single_object :: proc(handle: Handle, milliseconds: u32) -> u32 --- -} - -// @(default_calling_convention = "c") -foreign kernel32 { - @(link_name="GetLastError") get_last_error :: proc() -> i32 --- - @(link_name="CloseHandle") close_handle :: proc(h: Handle) -> i32 --- - - @(link_name="GetFileAttributesA") get_file_attributes_a :: proc(filename: cstring) -> u32 --- - @(link_name="GetFileAttributesW") get_file_attributes_w :: proc(filename: Wstring) -> u32 --- - @(link_name="GetFileAttributesExA") get_file_attributes_ex_a :: proc(filename: cstring, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: ^File_Attribute_Data) -> Bool --- - @(link_name="GetFileAttributesExW") get_file_attributes_ex_w :: proc(filename: Wstring, info_level_id: GET_FILEEX_INFO_LEVELS, file_info: ^File_Attribute_Data) -> Bool --- - @(link_name="CompareFileTime") compare_file_time :: proc(a, b: ^Filetime) -> i32 --- -} - -@(default_calling_convention = "c") -foreign kernel32 { - @(link_name="InterlockedCompareExchange") interlocked_compare_exchange :: proc(dst: ^i32, exchange, comparand: i32) -> i32 --- - @(link_name="InterlockedExchange") interlocked_exchange :: proc(dst: ^i32, desired: i32) -> i32 --- - @(link_name="InterlockedExchangeAdd") interlocked_exchange_add :: proc(dst: ^i32, desired: i32) -> i32 --- - @(link_name="InterlockedAnd") interlocked_and :: proc(dst: ^i32, desired: i32) -> i32 --- - @(link_name="InterlockedOr") interlocked_or :: proc(dst: ^i32, desired: i32) -> i32 --- - - @(link_name="InterlockedCompareExchange64") interlocked_compare_exchange64 :: proc(dst: ^i64, exchange, comparand: i64) -> i64 --- - @(link_name="InterlockedExchange64") interlocked_exchange64 :: proc(dst: ^i64, desired: i64) -> i64 --- - @(link_name="InterlockedExchangeAdd64") interlocked_exchange_add64 :: proc(dst: ^i64, desired: i64) -> i64 --- - @(link_name="InterlockedAnd64") interlocked_and64 :: proc(dst: ^i64, desired: i64) -> i64 --- - @(link_name="InterlockedOr64") interlocked_or64 :: proc(dst: ^i64, desired: i64) -> i64 --- -} - -@(default_calling_convention = "std") -foreign kernel32 { - @(link_name="_mm_pause") mm_pause :: proc() --- - @(link_name="ReadWriteBarrier") read_write_barrier :: proc() --- - @(link_name="WriteBarrier") write_barrier :: proc() --- - @(link_name="ReadBarrier") read_barrier :: proc() --- - - @(link_name="CreateThread") - create_thread :: proc(thread_attributes: ^Security_Attributes, stack_size: uint, start_routine: proc "stdcall" (rawptr) -> u32, - parameter: rawptr, creation_flags: u32, thread_id: ^u32) -> Handle --- - @(link_name="ResumeThread") resume_thread :: proc(thread: Handle) -> u32 --- - @(link_name="GetThreadPriority") get_thread_priority :: proc(thread: Handle) -> i32 --- - @(link_name="SetThreadPriority") set_thread_priority :: proc(thread: Handle, priority: i32) -> Bool --- - @(link_name="GetExitCodeThread") get_exit_code_thread :: proc(thread: Handle, exit_code: ^u32) -> Bool --- - @(link_name="TerminateThread") terminate_thread :: proc(thread: Handle, exit_code: u32) -> Bool --- - - @(link_name="InitializeCriticalSection") initialize_critical_section :: proc(critical_section: ^Critical_Section) --- - @(link_name="InitializeCriticalSectionAndSpinCount") initialize_critical_section_and_spin_count :: proc(critical_section: ^Critical_Section, spin_count: u32) -> b32 --- - @(link_name="DeleteCriticalSection") delete_critical_section :: proc(critical_section: ^Critical_Section) --- - @(link_name="SetCriticalSectionSpinCount") set_critical_section_spin_count :: proc(critical_section: ^Critical_Section, spin_count: u32) -> u32 --- - @(link_name="TryEnterCriticalSection") try_enter_critical_section :: proc(critical_section: ^Critical_Section) -> b8 --- - @(link_name="EnterCriticalSection") enter_critical_section :: proc(critical_section: ^Critical_Section) --- - @(link_name="LeaveCriticalSection") leave_critical_section :: proc(critical_section: ^Critical_Section) --- - - @(link_name="CreateEventA") create_event_a :: proc(event_attributes: ^Security_Attributes, manual_reset, initial_state: Bool, name: cstring) -> Handle --- - @(link_name="CreateEventW") create_event_w :: proc(event_attributes: ^Security_Attributes, manual_reset, initial_state: Bool, name: Wstring) -> Handle --- - @(link_name="PulseEvent") pulse_event :: proc(event: Handle) -> Bool --- - @(link_name="SetEvent") set_event :: proc(event: Handle) -> Bool --- - @(link_name="ResetEvent") reset_event :: proc(event: Handle) -> Bool --- - - @(link_name="LoadLibraryA") load_library_a :: proc(c_str: cstring) -> Hmodule --- - @(link_name="LoadLibraryW") load_library_w :: proc(c_str: Wstring) -> Hmodule --- - @(link_name="FreeLibrary") free_library :: proc(h: Hmodule) -> Bool --- - @(link_name="GetProcAddress") get_proc_address :: proc(h: Hmodule, c_str: cstring) -> rawptr --- - - @(link_name="GetFullPathNameA") get_full_path_name_a :: proc(filename: cstring, buffer_length: u32, buffer: cstring, file_part: ^Wstring) -> u32 --- - @(link_name="GetFullPathNameW") get_full_path_name_w :: proc(filename: Wstring, buffer_length: u32, buffer: Wstring, file_part: ^Wstring) -> u32 --- - @(link_name="GetLongPathNameA") get_long_path_name_a :: proc(short, long: cstring, len: u32) -> u32 --- - @(link_name="GetLongPathNameW") get_long_path_name_w :: proc(short, long: Wstring, len: u32) -> u32 --- - @(link_name="GetShortPathNameA") get_short_path_name_a :: proc(long, short: cstring, len: u32) -> u32 --- - @(link_name="GetShortPathNameW") get_short_path_name_w :: proc(long, short: Wstring, len: u32) -> u32 --- - - @(link_name="GetCurrentDirectoryA") get_current_directory_a :: proc(buffer_length: u32, buffer: cstring) -> u32 --- -} - -Memory_Basic_Information :: struct { - base_address: rawptr, - allocation_base: rawptr, - allocation_protect: u32, - region_size: uint, - state: u32, - protect: u32, - type: u32, -} - -@(default_calling_convention = "std") -foreign kernel32 { - @(link_name="VirtualAlloc") virtual_alloc :: proc(address: rawptr, size: uint, allocation_type: u32, protect: u32) -> rawptr --- - @(link_name="VirtualAllocEx") virtual_alloc_ex :: proc(process: Handle, address: rawptr, size: uint, allocation_type: u32, protect: u32) -> rawptr --- - @(link_name="VirtualFree") virtual_free :: proc(address: rawptr, size: uint, free_type: u32) -> Bool --- - @(link_name="VirtualLock") virtual_lock :: proc(address: rawptr, size: uint) -> Bool --- - @(link_name="VirtualProtect") virtual_protect :: proc(address: rawptr, size: uint, new_protect: u32, old_protect: ^u32) -> Bool --- - @(link_name="VirtualQuery") virtual_query :: proc(address: rawptr, buffer: ^Memory_Basic_Information, length: uint) -> uint --- -} - -MEM_COMMIT :: 0x00001000 -MEM_RESERVE :: 0x00002000 -MEM_DECOMMIT :: 0x00004000 -MEM_RELEASE :: 0x00008000 -MEM_RESET :: 0x00080000 -MEM_RESET_UNDO :: 0x01000000 - -MEM_LARGE_PAGES :: 0x20000000 -MEM_PHYSICAL :: 0x00400000 -MEM_TOP_DOWN :: 0x00100000 -MEM_WRITE_WATCH :: 0x00200000 - -PAGE_NOACCESS :: 0x01 -PAGE_READONLY :: 0x02 -PAGE_READWRITE :: 0x04 -PAGE_WRITECOPY :: 0x08 -PAGE_EXECUTE :: 0x10 -PAGE_EXECUTE_READ :: 0x20 -PAGE_EXECUTE_READWRITE :: 0x40 -PAGE_EXECUTE_WRITECOPY :: 0x80 diff --git a/core/sys/win32/ole32.odin b/core/sys/win32/ole32.odin deleted file mode 100644 index f4ee52399..000000000 --- a/core/sys/win32/ole32.odin +++ /dev/null @@ -1,18 +0,0 @@ -// +build windows -package win32 - -foreign import "system:ole32.lib" - -//objbase.h -Com_Init :: enum { - Multi_Threaded = 0x0, - Apartment_Threaded = 0x2, - Disable_OLE1_DDE = 0x4, - Speed_Over_Memory = 0x8, -} - -@(default_calling_convention = "std") -foreign ole32 { - @(link_name ="CoInitializeEx") com_init_ex :: proc(reserved: rawptr, co_init: Com_Init) ->Hresult --- - @(link_name = "CoUninitialize") com_shutdown :: proc() --- -} diff --git a/core/sys/win32/removal.odin b/core/sys/win32/removal.odin new file mode 100644 index 000000000..09c16aa05 --- /dev/null +++ b/core/sys/win32/removal.odin @@ -0,0 +1,3 @@ +package sys_win32 + +#panic(`"core:sys/win32" has been removed. Please use "core:sys/windows"`)
\ No newline at end of file diff --git a/core/sys/win32/shell32.odin b/core/sys/win32/shell32.odin deleted file mode 100644 index 3cedf0527..000000000 --- a/core/sys/win32/shell32.odin +++ /dev/null @@ -1,9 +0,0 @@ -// +build windows -package win32 - -foreign import "system:shell32.lib" - -@(default_calling_convention = "std") -foreign shell32 { - @(link_name="CommandLineToArgvW") command_line_to_argv_w :: proc(cmd_list: Wstring, num_args: ^i32) -> ^Wstring --- -} diff --git a/core/sys/win32/tests/general.odin b/core/sys/win32/tests/general.odin deleted file mode 100644 index 1a5fc911a..000000000 --- a/core/sys/win32/tests/general.odin +++ /dev/null @@ -1,41 +0,0 @@ -package win32_tests - -import "core:sys/win32" -import "core:testing" - -utf16_to_utf8 :: proc(t: ^testing.T, str: []u16, comparison: string, expected_result: bool, loc := #caller_location) { - result := win32.utf16_to_utf8(str[:]); - testing.expect(t, (result == comparison) == expected_result, "Incorrect utf16_to_utf8 conversion", loc); -} - -wstring_to_utf8 :: proc(t: ^testing.T, str: []u16, comparison: string, expected_result: bool, loc := #caller_location) { - result := win32.wstring_to_utf8(nil if len(str) == 0 else cast(win32.Wstring)&str[0], -1); - testing.expect(t, (result == comparison) == expected_result, "Incorrect wstring_to_utf8 conversion", loc); -} - -@test -test_utf :: proc(t: ^testing.T) { - utf16_to_utf8(t, []u16{}, "", true); - utf16_to_utf8(t, []u16{0}, "", true); - utf16_to_utf8(t, []u16{0, 't', 'e', 's', 't'}, "", true); - utf16_to_utf8(t, []u16{0, 't', 'e', 's', 't', 0}, "", true); - utf16_to_utf8(t, []u16{'t', 'e', 's', 't'}, "test", true); - utf16_to_utf8(t, []u16{'t', 'e', 's', 't', 0}, "test", true); - utf16_to_utf8(t, []u16{'t', 'e', 0, 's', 't'}, "te", true); - utf16_to_utf8(t, []u16{'t', 'e', 0, 's', 't', 0}, "te", true); - - wstring_to_utf8(t, []u16{}, "", true); - wstring_to_utf8(t, []u16{0}, "", true); - wstring_to_utf8(t, []u16{0, 't', 'e', 's', 't'}, "", true); - wstring_to_utf8(t, []u16{0, 't', 'e', 's', 't', 0}, "", true); - wstring_to_utf8(t, []u16{'t', 'e', 's', 't', 0}, "test", true); - wstring_to_utf8(t, []u16{'t', 'e', 0, 's', 't'}, "te", true); - wstring_to_utf8(t, []u16{'t', 'e', 0, 's', 't', 0}, "te", true); - - // WARNING: Passing a non-zero-terminated string to wstring_to_utf8 is dangerous, - // as it will go out of bounds looking for a zero. - // It will "fail" or "succeed" by having a zero just after the end of the input string or not. - wstring_to_utf8(t, []u16{'t', 'e', 's', 't'}, "test", false); - wstring_to_utf8(t, []u16{'t', 'e', 's', 't', 0}[:4], "test", true); - wstring_to_utf8(t, []u16{'t', 'e', 's', 't', 'q'}[:4], "test", false); -}
\ No newline at end of file diff --git a/core/sys/win32/user32.odin b/core/sys/win32/user32.odin deleted file mode 100644 index 44d1f7004..000000000 --- a/core/sys/win32/user32.odin +++ /dev/null @@ -1,289 +0,0 @@ -// +build windows -package win32 - -foreign import "system:user32.lib" - -import "core:intrinsics" - - -Menu_Bar_Info :: struct { - size: u32, - bar: Rect, - menu: Hmenu, - wnd_menu: Hwnd, - fields: u8, - // field.bar_focused: 1, - // field.focuses: 1, -} - -Menu_Item_Info_A :: struct { - size: u32, - mask: u32, - type: u32, - state: u32, - id: u32, - submenu: Hmenu, - bmp_checked: Hbitmap, - bmp_unchecked: Hbitmap, - item_data: u32, - type_data: cstring, - cch: u32, -} -Menu_Item_Info_W :: struct { - size: u32, - mask: u32, - type: u32, - state: u32, - id: u32, - submenu: Hmenu, - bmp_checked: Hbitmap, - bmp_unchecked: Hbitmap, - item_data: u32, - type_data: Wstring, - cch: u32, -} - -MF_BYCOMMAND :: 0x00000000 -MF_BYPOSITION :: 0x00000400 -MF_BITMAP :: 0x00000004 -MF_CHECKED :: 0x00000008 -MF_DISABLED :: 0x00000002 -MF_ENABLED :: 0x00000000 -MF_GRAYED :: 0x00000001 -MF_MENUBARBREAK :: 0x00000020 -MF_MENUBREAK :: 0x00000040 -MF_OWNERDRAW :: 0x00000100 -MF_POPUP :: 0x00000010 -MF_SEPARATOR :: 0x00000800 -MF_STRING :: 0x00000000 -MF_UNCHECKED :: 0x00000000 - -MB_ABORTRETRYIGNORE :: 0x00000002 -MB_CANCELTRYCONTINUE :: 0x00000006 -MB_HELP :: 0x00004000 -MB_OK :: 0x00000000 -MB_OKCANCEL :: 0x00000001 -MB_RETRYCANCEL :: 0x00000005 -MB_YESNO :: 0x00000004 -MB_YESNOCANCEL :: 0x00000003 - -MB_ICONEXCLAMATION :: 0x00000030 -MB_ICONWARNING :: 0x00000030 -MB_ICONINFORMATION :: 0x00000040 -MB_ICONASTERISK :: 0x00000040 -MB_ICONQUESTION :: 0x00000020 -MB_ICONSTOP :: 0x00000010 -MB_ICONERROR :: 0x00000010 -MB_ICONHAND :: 0x00000010 - -MB_DEFBUTTON1 :: 0x00000000 -MB_DEFBUTTON2 :: 0x00000100 -MB_DEFBUTTON3 :: 0x00000200 -MB_DEFBUTTON4 :: 0x00000300 - -MB_APPLMODAL :: 0x00000000 -MB_SYSTEMMODAL :: 0x00001000 -MB_TASKMODAL :: 0x00002000 - -MB_DEFAULT_DESKTOP_ONLY :: 0x00020000 -MB_RIGHT :: 0x00080000 -MB_RTLREADING :: 0x00100000 -MB_SETFOREGROUND :: 0x00010000 -MB_TOPMOST :: 0x00040000 -MB_SERVICE_NOTIFICATION :: 0x00200000 - - -@(default_calling_convention = "std") -foreign user32 { - @(link_name="GetDesktopWindow") get_desktop_window :: proc() -> Hwnd --- - when !intrinsics.is_package_imported("raylib") { // NOTE(bill): this is a bit of hack but it's to get around the namespace collisions - @(link_name="ShowCursor")show_cursor :: proc(show: Bool) -> i32 --- - } - @(link_name="GetCursorPos") get_cursor_pos :: proc(p: ^Point) -> Bool --- - @(link_name="SetCursorPos") set_cursor_pos :: proc(x, y: i32) -> Bool --- - @(link_name="GetCapure") get_capture :: proc(hwnd: Hwnd) -> Hwnd --- - @(link_name="SetCapture") set_capture :: proc(hwnd: Hwnd) -> Hwnd --- - @(link_name="ReleaseCapture") release_capture :: proc() -> Bool --- - @(link_name="ScreenToClient") screen_to_client :: proc(h: Hwnd, p: ^Point) -> Bool --- - @(link_name="ClientToScreen") client_to_screen :: proc(h: Hwnd, p: ^Point) -> Bool --- - @(link_name="PostQuitMessage") post_quit_message :: proc(exit_code: i32) --- - @(link_name="SetWindowTextA") set_window_text_a :: proc(hwnd: Hwnd, c_string: cstring) -> Bool --- - @(link_name="SetWindowTextW") set_window_text_w :: proc(hwnd: Hwnd, c_string: Wstring) -> Bool --- - @(link_name="RegisterClassA") register_class_a :: proc(wc: ^Wnd_Class_A) -> i16 --- - @(link_name="RegisterClassW") register_class_w :: proc(wc: ^Wnd_Class_W) -> i16 --- - @(link_name="UnregisterClassA") unregister_class_a :: proc(class_name: cstring, instance: Hinstance) -> Bool --- - @(link_name="UnregisterClassW") unregister_class_w :: proc(class_name: Wstring, instance: Hinstance) -> Bool --- - @(link_name="RegisterClassExA") register_class_ex_a :: proc(wc: ^Wnd_Class_Ex_A) -> i16 --- - @(link_name="RegisterClassExW") register_class_ex_w :: proc(wc: ^Wnd_Class_Ex_W) -> i16 --- - - @(link_name="CreateWindowExA") - create_window_ex_a :: proc(ex_style: u32, - class_name, title: cstring, - style: u32, - x, y, w, h: i32, - parent: Hwnd, menu: Hmenu, instance: Hinstance, - param: rawptr) -> Hwnd --- - - @(link_name="CreateWindowExW") - create_window_ex_w :: proc(ex_style: u32, - class_name, title: Wstring, - style: u32, - x, y, w, h: i32, - parent: Hwnd, menu: Hmenu, instance: Hinstance, - param: rawptr) -> Hwnd --- - - @(link_name="ShowWindow") show_window :: proc(hwnd: Hwnd, cmd_show: i32) -> Bool --- - @(link_name="TranslateMessage") translate_message :: proc(msg: ^Msg) -> Bool --- - @(link_name="DispatchMessageA") dispatch_message_a :: proc(msg: ^Msg) -> Lresult --- - @(link_name="DispatchMessageW") dispatch_message_w :: proc(msg: ^Msg) -> Lresult --- - @(link_name="UpdateWindow") update_window :: proc(hwnd: Hwnd) -> Bool --- - @(link_name="GetMessageA") get_message_a :: proc(msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max: u32) -> Bool --- - @(link_name="GetMessageW") get_message_w :: proc(msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max: u32) -> Bool --- - - @(link_name="PeekMessageA") peek_message_a :: proc(msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool --- - @(link_name="PeekMessageW") peek_message_w :: proc(msg: ^Msg, hwnd: Hwnd, msg_filter_min, msg_filter_max, remove_msg: u32) -> Bool --- - - - @(link_name="PostMessageA") post_message_a :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Bool --- - @(link_name="PostMessageW") post_message_w :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Bool --- - @(link_name="SendMessageA") send_message_a :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult --- - @(link_name="SendMessageW") send_message_w :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult --- - - @(link_name="DefWindowProcA") def_window_proc_a :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult --- - @(link_name="DefWindowProcW") def_window_proc_w :: proc(hwnd: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Lresult --- - - @(link_name="AdjustWindowRect") adjust_window_rect :: proc(rect: ^Rect, style: u32, menu: Bool) -> Bool --- - @(link_name="GetActiveWindow") get_active_window :: proc() -> Hwnd --- - - @(link_name="DestroyWindow") destroy_window :: proc(wnd: Hwnd) -> Bool --- - @(link_name="DescribePixelFormat") describe_pixel_format :: proc(dc: Hdc, pixel_format: i32, bytes: u32, pfd: ^Pixel_Format_Descriptor) -> i32 --- - - @(link_name="GetMonitorInfoA") get_monitor_info_a :: proc(monitor: Hmonitor, mi: ^Monitor_Info) -> Bool --- - @(link_name="MonitorFromWindow") monitor_from_window :: proc(wnd: Hwnd, flags: u32) -> Hmonitor --- - - @(link_name="SetWindowPos") set_window_pos :: proc(wnd: Hwnd, wndInsertAfter: Hwnd, x, y, width, height: i32, flags: u32) -> Bool --- - - @(link_name="GetWindowPlacement") get_window_placement :: proc(wnd: Hwnd, wndpl: ^Window_Placement) -> Bool --- - @(link_name="SetWindowPlacement") set_window_placement :: proc(wnd: Hwnd, wndpl: ^Window_Placement) -> Bool --- - @(link_name="GetWindowRect") get_window_rect :: proc(wnd: Hwnd, rect: ^Rect) -> Bool --- - - @(link_name="GetWindowLongPtrA") get_window_long_ptr_a :: proc(wnd: Hwnd, index: i32) -> Long_Ptr --- - @(link_name="SetWindowLongPtrA") set_window_long_ptr_a :: proc(wnd: Hwnd, index: i32, new: Long_Ptr) -> Long_Ptr --- - @(link_name="GetWindowLongPtrW") get_window_long_ptr_w :: proc(wnd: Hwnd, index: i32) -> Long_Ptr --- - @(link_name="SetWindowLongPtrW") set_window_long_ptr_w :: proc(wnd: Hwnd, index: i32, new: Long_Ptr) -> Long_Ptr --- - - @(link_name="GetWindowText") get_window_text :: proc(wnd: Hwnd, str: cstring, maxCount: i32) -> i32 --- - - @(link_name="GetClientRect") get_client_rect :: proc(hwnd: Hwnd, rect: ^Rect) -> Bool --- - - @(link_name="GetDC") get_dc :: proc(h: Hwnd) -> Hdc --- - @(link_name="ReleaseDC") release_dc :: proc(wnd: Hwnd, hdc: Hdc) -> i32 --- - - @(link_name="MapVirtualKeyA") map_virtual_key_a :: proc(scancode: u32, map_type: u32) -> u32 --- - @(link_name="MapVirtualKeyW") map_virtual_key_w :: proc(scancode: u32, map_type: u32) -> u32 --- - - @(link_name="GetKeyState") get_key_state :: proc(v_key: i32) -> i16 --- - @(link_name="GetAsyncKeyState") get_async_key_state :: proc(v_key: i32) -> i16 --- - - @(link_name="SetForegroundWindow") set_foreground_window :: proc(h: Hwnd) -> Bool --- - @(link_name="SetFocus") set_focus :: proc(h: Hwnd) -> Hwnd --- - - - @(link_name="LoadImageA") load_image_a :: proc(instance: Hinstance, name: cstring, type_: u32, x_desired, y_desired : i32, load : u32) -> Handle --- - @(link_name="LoadIconA") load_icon_a :: proc(instance: Hinstance, icon_name: cstring) -> Hicon --- - @(link_name="DestroyIcon") destroy_icon :: proc(icon: Hicon) -> Bool --- - - @(link_name="LoadCursorA") load_cursor_a :: proc(instance: Hinstance, cursor_name: cstring) -> Hcursor --- - @(link_name="LoadCursorW") load_cursor_w :: proc(instance: Hinstance, cursor_name: Wstring) -> Hcursor --- - @(link_name="GetCursor") get_cursor :: proc() -> Hcursor --- - @(link_name="SetCursor") set_cursor :: proc(cursor: Hcursor) -> Hcursor --- - - @(link_name="RegisterRawInputDevices") register_raw_input_devices :: proc(raw_input_device: ^Raw_Input_Device, num_devices, size: u32) -> Bool --- - - @(link_name="GetRawInputData") get_raw_input_data :: proc(raw_input: Hrawinput, command: u32, data: rawptr, size: ^u32, size_header: u32) -> u32 --- - - @(link_name="MapVirtualKeyExW") map_virtual_key_ex_w :: proc(code, map_type: u32, hkl: HKL) -> u32 --- - @(link_name="MapVirtualKeyExA") map_virtual_key_ex_a :: proc(code, map_type: u32, hkl: HKL) -> u32 --- - - @(link_name="EnumDisplayMonitors") enum_display_monitors :: proc(hdc: Hdc, rect: ^Rect, enum_proc: Monitor_Enum_Proc, lparam: Lparam) -> bool --- - - @(link_name="EnumDisplaySettingsA") enum_display_settings_a :: proc(device_name: cstring, mode_number: u32, mode: ^Dev_Mode_A) -> Bool --- -} - -@(default_calling_convention = "std") -foreign user32 { - @(link_name="CreateMenu") create_menu :: proc() -> Hmenu --- - @(link_name="CreatePopupMenu") create_popup_menu :: proc() -> Hmenu --- - @(link_name="DestroyMenu") destroy_menu :: proc(menu: Hmenu) -> Bool --- - @(link_name="DeleteMenu") delete_menu :: proc(menu: Hmenu, position: u32, flags: u32) -> Bool --- - - @(link_name="EnableMenuItem") enable_menu_item :: proc(menu: Hmenu, id_enable_itme: i32, enable: u32) -> Bool --- - @(link_name="EndMenu") end_menu :: proc(menu: Hmenu, flags: u32, id_new_item: Uint_Ptr, new_item: cstring) -> Bool --- - @(link_name="GetMenu") get_menu :: proc(wnd: Hwnd) -> Hmenu --- - @(link_name="GetMenuBarInfo") get_menu_bar_info :: proc(wnd: Hwnd, id_object, id_item: u32, mbi: ^Menu_Bar_Info) -> Hmenu --- - @(link_name="GetMenuStringA") get_menu_string_a :: proc(menu: Hmenu, id_item: u32, s: cstring, cch_max: i32, flags: u32) -> i32 --- - @(link_name="GetMenuStringW") get_menu_string_w :: proc(menu: Hmenu, id_item: u32, s: Wstring, cch_max: i32, flags: u32) -> i32 --- - @(link_name="GetMenuState") get_menu_state :: proc(menu: Hmenu, id: u32, flags: u32) -> u32 --- - @(link_name="GetMenuItemRect") get_menu_item_rect :: proc(wnd: Hwnd, menu: Hmenu, id_item: u32, item: ^Rect) -> Bool --- - - @(link_name="SetMenu") set_menu :: proc(wnd: Hwnd, menu: Hmenu) -> Bool --- - - @(link_name="DrawMenuBar") draw_menu_bar :: proc(wnd: Hwnd) -> Bool --- - @(link_name="InsertMenuA") insert_menu_a :: proc(menu: Hmenu, position: u32, flags: u32, id_new_item: Uint_Ptr, new_item: cstring) -> Bool --- - @(link_name="InsertMenuW") insert_menu_w :: proc(menu: Hmenu, position: u32, flags: u32, id_new_item: Uint_Ptr, new_item: Wstring) -> Bool --- - - @(link_name="InsertMenuItemA") insert_menu_item_a :: proc(hmenu: Hmenu, item: u32, fByPosition: Bool, lpmi: ^Menu_Item_Info_A) -> Bool --- - @(link_name="InsertMenuItemW") insert_menu_item_w :: proc(hmenu: Hmenu, item: u32, fByPosition: Bool, lpmi: ^Menu_Item_Info_W) -> Bool --- - - @(link_name="AppendMenuA") append_menu_a :: proc(menu: Hmenu, flags: u32, id_new_item: Uint_Ptr, new_item: cstring) -> Bool --- - @(link_name="AppendMenuW") append_menu_w :: proc(menu: Hmenu, flags: u32, id_new_item: Uint_Ptr, new_item: Wstring) -> Bool --- - - @(link_name="CheckMenuItem") check_menu_item :: proc(menu: Hmenu, id_check_item: u32, check: u32) -> u32 --- - @(link_name="CheckMenuRadioItem") check_menu_radio_item :: proc(menu: Hmenu, first, last: u32, check: u32, flags: u32) -> Bool --- - - @(link_name="GetPropA") get_prop_a :: proc(wnd: Hwnd, s: cstring) -> Handle --- - @(link_name="GetPropW") get_prop_w :: proc(wnd: Hwnd, s: Wstring) -> Handle --- - - @(link_name="MessageBoxA") message_box_a :: proc(wnd: Hwnd, text, caption: cstring, type: u32) -> i32 --- - @(link_name="MessageBoxW") message_box_w :: proc(wnd: Hwnd, text, caption: Wstring, type: u32) -> i32 --- - - @(link_name="MessageBoxExA") message_box_ex_a :: proc(wnd: Hwnd, text, caption: cstring, type: u32, language_id: u16) -> i32 --- - @(link_name="MessageBoxExW") message_box_ex_w :: proc(wnd: Hwnd, text, caption: Wstring, type: u32, language_id: u16) -> i32 --- - - @(link_name="BeginPaint") begin_paint :: proc(wnd: Hwnd, paint: ^Paint_Struct) -> Hdc --- - @(link_name="EndPaint") end_paint :: proc(wnd: Hwnd, paint: ^Paint_Struct) -> Bool --- -} - - -_IDC_APPSTARTING := rawptr(uintptr(32650)) -_IDC_ARROW := rawptr(uintptr(32512)) -_IDC_CROSS := rawptr(uintptr(32515)) -_IDC_HAND := rawptr(uintptr(32649)) -_IDC_HELP := rawptr(uintptr(32651)) -_IDC_IBEAM := rawptr(uintptr(32513)) -_IDC_ICON := rawptr(uintptr(32641)) -_IDC_NO := rawptr(uintptr(32648)) -_IDC_SIZE := rawptr(uintptr(32640)) -_IDC_SIZEALL := rawptr(uintptr(32646)) -_IDC_SIZENESW := rawptr(uintptr(32643)) -_IDC_SIZENS := rawptr(uintptr(32645)) -_IDC_SIZENWSE := rawptr(uintptr(32642)) -_IDC_SIZEWE := rawptr(uintptr(32644)) -_IDC_UPARROW := rawptr(uintptr(32516)) -_IDC_WAIT := rawptr(uintptr(32514)) -IDC_APPSTARTING := cstring(_IDC_APPSTARTING) -IDC_ARROW := cstring(_IDC_ARROW) -IDC_CROSS := cstring(_IDC_CROSS) -IDC_HAND := cstring(_IDC_HAND) -IDC_HELP := cstring(_IDC_HELP) -IDC_IBEAM := cstring(_IDC_IBEAM) -IDC_ICON := cstring(_IDC_ICON) -IDC_NO := cstring(_IDC_NO) -IDC_SIZE := cstring(_IDC_SIZE) -IDC_SIZEALL := cstring(_IDC_SIZEALL) -IDC_SIZENESW := cstring(_IDC_SIZENESW) -IDC_SIZENS := cstring(_IDC_SIZENS) -IDC_SIZENWSE := cstring(_IDC_SIZENWSE) -IDC_SIZEWE := cstring(_IDC_SIZEWE) -IDC_UPARROW := cstring(_IDC_UPARROW) -IDC_WAIT := cstring(_IDC_WAIT) diff --git a/core/sys/win32/wgl.odin b/core/sys/win32/wgl.odin deleted file mode 100644 index e6c414b0e..000000000 --- a/core/sys/win32/wgl.odin +++ /dev/null @@ -1,114 +0,0 @@ -// +build windows -package win32 - -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 -Color_Ref :: distinct u32 - -Layer_Plane_Descriptor :: struct { - size: u16, - version: u16, - flags: u32, - pixel_type: u8, - color_bits: u8, - red_bits: u8, - red_shift: u8, - green_bits: u8, - green_shift: u8, - blue_bits: u8, - blue_shift: u8, - alpha_bits: u8, - alpha_shift: u8, - accum_bits: u8, - accum_red_bits: u8, - accum_green_bits: u8, - accum_blue_bits: u8, - accum_alpha_bits: u8, - depth_bits: u8, - stencil_bits: u8, - aux_buffers: u8, - layer_type: u8, - reserved: u8, - transparent: Color_Ref, -} - -Point_Float :: struct {x, y: f32} - -Glyph_Metrics_Float :: struct { - black_box_x: f32, - black_box_y: f32, - glyph_origin: Point_Float, - cell_inc_x: f32, - cell_inc_y: f32, -} - -Create_Context_Attribs_ARB_Type :: #type proc "c" (hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc -Choose_Pixel_Format_ARB_Type :: #type proc "c" (hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool -Swap_Interval_EXT_Type :: #type proc "c" (interval: i32) -> bool -Get_Extensions_String_ARB_Type :: #type proc "c" (Hdc) -> cstring - -// Procedures - create_context_attribs_arb: Create_Context_Attribs_ARB_Type - choose_pixel_format_arb: Choose_Pixel_Format_ARB_Type - swap_interval_ext: Swap_Interval_EXT_Type - get_extensions_string_arb: Get_Extensions_String_ARB_Type - - -foreign opengl32 { - @(link_name="wglCreateContext") - create_context :: proc(hdc: Hdc) -> Hglrc --- - - @(link_name="wglMakeCurrent") - make_current :: proc(hdc: Hdc, hglrc: Hglrc) -> Bool --- - - @(link_name="wglGetProcAddress") - get_gl_proc_address :: proc(c_str: cstring) -> rawptr --- - - @(link_name="wglDeleteContext") - delete_context :: proc(hglrc: Hglrc) -> Bool --- - - @(link_name="wglCopyContext") - copy_context :: proc(src, dst: Hglrc, mask: u32) -> Bool --- - - @(link_name="wglCreateLayerContext") - create_layer_context :: proc(hdc: Hdc, layer_plane: i32) -> Hglrc --- - - @(link_name="wglDescribeLayerPlane") - describe_layer_plane :: proc(hdc: Hdc, pixel_format, layer_plane: i32, bytes: u32, pd: ^Layer_Plane_Descriptor) -> Bool --- - - @(link_name="wglGetCurrentContext") - get_current_context :: proc() -> Hglrc --- - - @(link_name="wglGetCurrentDC") - get_current_dc :: proc() -> Hdc --- - - @(link_name="wglGetLayerPaletteEntries") - get_layer_palette_entries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr: ^Color_Ref) -> i32 --- - - @(link_name="wglRealizeLayerPalette") - realize_layer_palette :: proc(hdc: Hdc, layer_plane: i32, realize: Bool) -> Bool --- - - @(link_name="wglSetLayerPaletteEntries") - set_layer_palette_entries :: proc(hdc: Hdc, layer_plane, start, entries: i32, cr: ^Color_Ref) -> i32 --- - - @(link_name="wglShareLists") - share_lists :: proc(hglrc1, hglrc2: Hglrc) -> Bool --- - - @(link_name="wglSwapLayerBuffers") - swap_layer_buffers :: proc(hdc: Hdc, planes: u32) -> Bool --- - - @(link_name="wglUseFontBitmaps") - use_font_bitmaps :: proc(hdc: Hdc, first, count, list_base: u32) -> Bool --- - - @(link_name="wglUseFontOutlines") - use_font_outlines :: proc(hdc: Hdc, first, count, list_base: u32, deviation, extrusion: f32, format: i32, gmf: ^Glyph_Metrics_Float) -> Bool --- -} diff --git a/core/sys/win32/winmm.odin b/core/sys/win32/winmm.odin deleted file mode 100644 index 0f567fbcc..000000000 --- a/core/sys/win32/winmm.odin +++ /dev/null @@ -1,12 +0,0 @@ -// +build windows -package win32 - -foreign import "system:winmm.lib" - - -@(default_calling_convention = "std") -foreign winmm { - @(link_name="timeBeginPeriod") time_begin_period :: proc(period: u32) -> u32 --- - - @(link_name="timeGetTime") time_get_time :: proc() -> u32 --- -} diff --git a/core/sys/windows/advapi32.odin b/core/sys/windows/advapi32.odin index a2a24242f..20badb5da 100644 --- a/core/sys/windows/advapi32.odin +++ b/core/sys/windows/advapi32.odin @@ -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 diff --git a/core/sys/windows/bcrypt.odin b/core/sys/windows/bcrypt.odin index ed28d5b7f..52eb4b1b6 100644 --- a/core/sys/windows/bcrypt.odin +++ b/core/sys/windows/bcrypt.odin @@ -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 --- } diff --git a/core/sys/windows/bluetooth.odin b/core/sys/windows/bluetooth.odin index c9f6bcc93..c2534896b 100644 --- a/core/sys/windows/bluetooth.odin +++ b/core/sys/windows/bluetooth.odin @@ -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 --- }
\ No newline at end of file diff --git a/core/sys/win32/comdlg32.odin b/core/sys/windows/comdlg32.odin index 1e0d5c3ca..a3709cba7 100644 --- a/core/sys/win32/comdlg32.odin +++ b/core/sys/windows/comdlg32.odin @@ -1,70 +1,44 @@ // +build windows -package win32 +package sys_windows -foreign import "system:comdlg32.lib" +foreign import "system:Comdlg32.lib" import "core:strings" -OFN_Hook_Proc :: #type proc "stdcall" (hdlg: Hwnd, msg: u32, wparam: Wparam, lparam: Lparam) -> Uint_Ptr - -Open_File_Name_A :: struct { - struct_size: u32, - hwnd_owner: Hwnd, - instance: Hinstance, - filter: cstring, - custom_filter: cstring, - max_cust_filter: u32, - filter_index: u32, - file: cstring, - max_file: u32, - file_title: cstring, - max_file_title: u32, - initial_dir: cstring, - title: cstring, - flags: u32, - file_offset: u16, - file_extension: u16, - def_ext: cstring, - cust_data: Lparam, - hook: OFN_Hook_Proc, - template_name: cstring, - pv_reserved: rawptr, - dw_reserved: u32, - flags_ex: u32, +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, } -Open_File_Name_W :: struct { - struct_size: u32, - hwnd_owner: Hwnd, - instance: Hinstance, - filter: Wstring, - custom_filter: Wstring, - max_cust_filter: u32, - filter_index: u32, - file: Wstring, - max_file: u32, - file_title: Wstring, - max_file_title: u32, - initial_dir: Wstring, - title: Wstring, - flags: u32, - file_offset: u16, - file_extension: u16, - def_ext: Wstring, - cust_data: Lparam, - hook: OFN_Hook_Proc, - template_name: Wstring, - pv_reserved: rawptr, - dw_reserved: u32, - flags_ex: u32, -} - -@(default_calling_convention = "c") -foreign comdlg32 { - @(link_name="GetOpenFileNameA") get_open_file_name_a :: proc(arg1: ^Open_File_Name_A) -> Bool --- - @(link_name="GetOpenFileNameW") get_open_file_name_w :: proc(arg1: ^Open_File_Name_W) -> Bool --- - @(link_name="GetSaveFileNameA") get_save_file_name_a :: proc(arg1: ^Open_File_Name_A) -> Bool --- - @(link_name="GetSaveFileNameW") get_save_file_name_w :: proc(arg1: ^Open_File_Name_W) -> Bool --- - @(link_name="CommDlgExtendedError") comm_dlg_extended_error :: proc() -> u32 --- +@(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" @@ -100,23 +74,23 @@ _open_file_dialog :: proc(title: string, dir: string, filter = strings.join(filters, "\u0000", context.temp_allocator) filter = strings.concatenate({filter, "\u0000"}, context.temp_allocator) - ofn := Open_File_Name_W{ - struct_size = size_of(Open_File_Name_W), - file = Wstring(&file_buf[0]), - max_file = MAX_PATH_WIDE, - title = utf8_to_wstring(title, context.temp_allocator), - filter = utf8_to_wstring(filter, context.temp_allocator), - initial_dir = utf8_to_wstring(dir, context.temp_allocator), - filter_index = u32(clamp(default_filter, 1, filter_len / 2)), - def_ext = utf8_to_wstring(default_ext, context.temp_allocator), - flags = u32(flags), + 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(get_open_file_name_w(&ofn)) + ok = bool(GetOpenFileNameW(&ofn)) case .Save: - ok = bool(get_save_file_name_w(&ofn)) + ok = bool(GetSaveFileNameW(&ofn)) case: ok = false } @@ -124,9 +98,9 @@ _open_file_dialog :: proc(title: string, dir: string, if !ok { return } - - file_name := utf16_to_utf8(file_buf[:], allocator) + + file_name, _ := utf16_to_utf8(file_buf[:], allocator) path = strings.trim_right_null(file_name) return } @@ -140,9 +114,9 @@ select_file_to_open :: proc(title := OPEN_TITLE, dir := ".", } 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) { + 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 diff --git a/core/sys/windows/gdi32.odin b/core/sys/windows/gdi32.odin index 15d5567c7..898766361 100644 --- a/core/sys/windows/gdi32.odin +++ b/core/sys/windows/gdi32.odin @@ -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} +} diff --git a/core/sys/windows/kernel32.odin b/core/sys/windows/kernel32.odin index 8e1b8d442..b44aa0305 100644 --- a/core/sys/windows/kernel32.odin +++ b/core/sys/windows/kernel32.odin @@ -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, +}
\ No newline at end of file diff --git a/core/sys/windows/ntdll.odin b/core/sys/windows/ntdll.odin index 5deffd9f9..dda5b9711 100644 --- a/core/sys/windows/ntdll.odin +++ b/core/sys/windows/ntdll.odin @@ -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 --- }
\ No newline at end of file diff --git a/core/sys/windows/ole32.odin b/core/sys/windows/ole32.odin new file mode 100644 index 000000000..23fe888d2 --- /dev/null +++ b/core/sys/windows/ole32.odin @@ -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() --- +} diff --git a/core/sys/windows/shell32.odin b/core/sys/windows/shell32.odin index 70d8943bd..a6ecefc32 100644 --- a/core/sys/windows/shell32.odin +++ b/core/sys/windows/shell32.odin @@ -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 --- } diff --git a/core/sys/windows/shlwapi.odin b/core/sys/windows/shlwapi.odin new file mode 100644 index 000000000..1852d536f --- /dev/null +++ b/core/sys/windows/shlwapi.odin @@ -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 --- +} diff --git a/core/sys/windows/synchronization.odin b/core/sys/windows/synchronization.odin index c4e1d2188..c98730aa0 100644 --- a/core/sys/windows/synchronization.odin +++ b/core/sys/windows/synchronization.odin @@ -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) --- } diff --git a/core/sys/windows/system_params.odin b/core/sys/windows/system_params.odin new file mode 100644 index 000000000..e94d777bf --- /dev/null +++ b/core/sys/windows/system_params.odin @@ -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 diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index de19cd6cc..a0649c5f3 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -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 +}
\ No newline at end of file diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index 2316d3363..1b6d23ba4 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -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 } diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin index d464007d3..1c8b9175b 100644 --- a/core/sys/windows/util.odin +++ b/core/sys/windows/util.odin @@ -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 + } } diff --git a/core/sys/windows/wgl.odin b/core/sys/windows/wgl.odin new file mode 100644 index 000000000..689a41dea --- /dev/null +++ b/core/sys/windows/wgl.odin @@ -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 --- +} diff --git a/core/sys/windows/winmm.odin b/core/sys/windows/winmm.odin new file mode 100644 index 000000000..17f4d8e86 --- /dev/null +++ b/core/sys/windows/winmm.odin @@ -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 --- +} diff --git a/core/sys/windows/ws2_32.odin b/core/sys/windows/ws2_32.odin index 0cff5c2da..09af86bce 100644 --- a/core/sys/windows/ws2_32.odin +++ b/core/sys/windows/ws2_32.odin @@ -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, |