From fa6271bad6bdc5fb1173824a88855b9268ea6f3d Mon Sep 17 00:00:00 2001 From: SuperAuguste <19855629+SuperAuguste@users.noreply.github.com> Date: Fri, 24 Nov 2023 13:04:54 -0500 Subject: [PATCH] shell32 and ole32 removed from std --- known-folders.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/known-folders.zig b/known-folders.zig index 83ed91e..f7ca20f 100644 --- a/known-folders.zig +++ b/known-folders.zig @@ -58,19 +58,29 @@ pub fn getPath(allocator: std.mem.Allocator, folder: KnownFolder) Error!?[]const switch (builtin.os.tag) { .windows => { + const funcs = struct { + extern "shell32" fn SHGetKnownFolderPath( + rfid: *const std.os.windows.GUID, + dwFlags: std.os.windows.DWORD, + hToken: ?std.os.windows.HANDLE, + ppszPathL: *std.os.windows.PWSTR, + ) callconv(std.os.windows.WINAPI) std.os.windows.HRESULT; + extern "ole32" fn CoTaskMemFree(pv: std.os.windows.LPVOID) callconv(std.os.windows.WINAPI) void; + }; + const folder_spec = windows_folder_spec.get(folder); switch (folder_spec) { .by_guid => |guid| { var dir_path_ptr: [*:0]u16 = undefined; - switch (std.os.windows.shell32.SHGetKnownFolderPath( + switch (funcs.SHGetKnownFolderPath( &guid, std.os.windows.KF_FLAG_CREATE, // TODO: Chose sane option here? null, &dir_path_ptr, )) { std.os.windows.S_OK => { - defer std.os.windows.ole32.CoTaskMemFree(@ptrCast(dir_path_ptr)); + defer funcs.CoTaskMemFree(@ptrCast(dir_path_ptr)); const global_dir = std.unicode.utf16leToUtf8Alloc(allocator, std.mem.span(dir_path_ptr)) catch |err| switch (err) { error.UnexpectedSecondSurrogateHalf => return null, error.ExpectedSecondSurrogateHalf => return null,