shell32 and ole32 removed from std

This commit is contained in:
SuperAuguste 2023-11-24 13:04:54 -05:00
parent 855473062e
commit fa6271bad6

View File

@ -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,