| author | |
| committer | |
| log | aaf1e0b25bbeedc18869073e1a51719e2e86cc93 |
| tree | d08d49431f9bc3f23d13e226a5308aaa645491e0 |
| parent | 4a1a5ee47b60eb697ed814d7b1eb6f5c45d65f5a |
| signature |
3 files changed, 44 insertions(+), 3 deletions(-)
lib/std/dynamic_library.zig+15-3| ... | @@ -320,16 +320,28 @@ pub const WindowsDynLib = struct { | ... | @@ -320,16 +320,28 @@ pub const WindowsDynLib = struct { |
| 320 | dll: windows.HMODULE, | 320 | dll: windows.HMODULE, |
| 321 | 321 | ||
| 322 | pub fn open(path: []const u8) !WindowsDynLib { | 322 | pub fn open(path: []const u8) !WindowsDynLib { |
| 323 | return openEx(path, .none); | ||
| 324 | } | ||
| 325 | |||
| 326 | pub fn openEx(path: []const u8, flags: windows.LoadLibraryFlags) !WindowsDynLib { | ||
| 323 | const path_w = try windows.sliceToPrefixedFileW(null, path); | 327 | const path_w = try windows.sliceToPrefixedFileW(null, path); |
| 324 | return openW(path_w.span().ptr); | 328 | return openExW(path_w.span().ptr, flags); |
| 325 | } | 329 | } |
| 326 | 330 | ||
| 327 | pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib { | 331 | pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib { |
| 332 | return openExZ(path_c, .none); | ||
| 333 | } | ||
| 334 | |||
| 335 | pub fn openExZ(path_c: [*:0]const u8, flags: windows.LoadLibraryFlags) !WindowsDynLib { | ||
| 328 | const path_w = try windows.cStrToPrefixedFileW(null, path_c); | 336 | const path_w = try windows.cStrToPrefixedFileW(null, path_c); |
| 329 | return openW(path_w.span().ptr); | 337 | return openExW(path_w.span().ptr, flags); |
| 330 | } | 338 | } |
| 331 | 339 | ||
| 332 | pub fn openW(path_w: [*:0]const u16) !WindowsDynLib { | 340 | pub fn openW(path_w: [*:0]const u16) !WindowsDynLib { |
| 341 | return openExW(path_w, .none); | ||
| 342 | } | ||
| 343 | |||
| 344 | pub fn openExW(path_w: [*:0]const u16, flags: windows.LoadLibraryFlags) !WindowsDynLib { | ||
| 333 | var offset: usize = 0; | 345 | var offset: usize = 0; |
| 334 | if (path_w[0] == '\\' and path_w[1] == '?' and path_w[2] == '?' and path_w[3] == '\\') { | 346 | if (path_w[0] == '\\' and path_w[1] == '?' and path_w[2] == '?' and path_w[3] == '\\') { |
| 335 | // + 4 to skip over the \??\ | 347 | // + 4 to skip over the \??\ |
| ... | @@ -337,7 +349,7 @@ pub const WindowsDynLib = struct { | ... | @@ -337,7 +349,7 @@ pub const WindowsDynLib = struct { |
| 337 | } | 349 | } |
| 338 | 350 | ||
| 339 | return WindowsDynLib{ | 351 | return WindowsDynLib{ |
| 340 | .dll = try windows.LoadLibraryW(path_w + offset), | 352 | .dll = try windows.LoadLibraryExW(path_w + offset, flags), |
| 341 | }; | 353 | }; |
| 342 | } | 354 | } |
| 343 | 355 |
lib/std/os/windows.zig+28| ... | @@ -1802,6 +1802,34 @@ pub fn LoadLibraryW(lpLibFileName: [*:0]const u16) LoadLibraryError!HMODULE { | ... | @@ -1802,6 +1802,34 @@ pub fn LoadLibraryW(lpLibFileName: [*:0]const u16) LoadLibraryError!HMODULE { |
| 1802 | }; | 1802 | }; |
| 1803 | } | 1803 | } |
| 1804 | 1804 | ||
| 1805 | pub const LoadLibraryFlags = enum(DWORD) { | ||
| 1806 | none = 0, | ||
| 1807 | dont_resolve_dll_references = 0x00000001, | ||
| 1808 | load_ignore_code_authz_level = 0x00000010, | ||
| 1809 | load_library_as_datafile = 0x00000002, | ||
| 1810 | load_library_as_datafile_exclusive = 0x00000040, | ||
| 1811 | load_library_as_image_resource = 0x00000020, | ||
| 1812 | load_library_search_application_dir = 0x00000200, | ||
| 1813 | load_library_search_default_dirs = 0x00001000, | ||
| 1814 | load_library_search_dll_load_dir = 0x00000100, | ||
| 1815 | load_library_search_system32 = 0x00000800, | ||
| 1816 | load_library_search_user_dirs = 0x00000400, | ||
| 1817 | load_with_altered_search_path = 0x00000008, | ||
| 1818 | load_library_require_signed_target = 0x00000080, | ||
| 1819 | load_library_safe_current_dirs = 0x00002000, | ||
| 1820 | }; | ||
| 1821 | |||
| 1822 | pub fn LoadLibraryExW(lpLibFileName: [*:0]const u16, dwFlags: LoadLibraryFlags) LoadLibraryError!HMODULE { | ||
| 1823 | return kernel32.LoadLibraryExW(lpLibFileName, null, @intFromEnum(dwFlags)) orelse { | ||
| 1824 | switch (kernel32.GetLastError()) { | ||
| 1825 | .FILE_NOT_FOUND => return error.FileNotFound, | ||
| 1826 | .PATH_NOT_FOUND => return error.FileNotFound, | ||
| 1827 | .MOD_NOT_FOUND => return error.FileNotFound, | ||
| 1828 | else => |err| return unexpectedError(err), | ||
| 1829 | } | ||
| 1830 | }; | ||
| 1831 | } | ||
| 1832 | |||
| 1805 | pub fn FreeLibrary(hModule: HMODULE) void { | 1833 | pub fn FreeLibrary(hModule: HMODULE) void { |
| 1806 | assert(kernel32.FreeLibrary(hModule) != 0); | 1834 | assert(kernel32.FreeLibrary(hModule) != 0); |
| 1807 | } | 1835 | } |
lib/std/os/windows/kernel32.zig+1| ... | @@ -387,6 +387,7 @@ pub extern "kernel32" fn WriteFileEx( | ... | @@ -387,6 +387,7 @@ pub extern "kernel32" fn WriteFileEx( |
| 387 | ) callconv(WINAPI) BOOL; | 387 | ) callconv(WINAPI) BOOL; |
| 388 | 388 | ||
| 389 | pub extern "kernel32" fn LoadLibraryW(lpLibFileName: [*:0]const u16) callconv(WINAPI) ?HMODULE; | 389 | pub extern "kernel32" fn LoadLibraryW(lpLibFileName: [*:0]const u16) callconv(WINAPI) ?HMODULE; |
| 390 | pub extern "kernel32" fn LoadLibraryExW(lpLibFileName: [*:0]const u16, hFile: ?HANDLE, dwFlags: DWORD) callconv(WINAPI) ?HMODULE; | ||
| 390 | 391 | ||
| 391 | pub extern "kernel32" fn GetProcAddress(hModule: HMODULE, lpProcName: [*:0]const u8) callconv(WINAPI) ?FARPROC; | 392 | pub extern "kernel32" fn GetProcAddress(hModule: HMODULE, lpProcName: [*:0]const u8) callconv(WINAPI) ?FARPROC; |
| 392 | 393 |