marlersoft / zigwin32

Zig bindings for Win32 generated by https://github.com/marlersoft/zigwin32gen
MIT License
234 stars 30 forks source link

Adding Microsofts Macro to cast WIN32_ERROR codes into HRESULT's #34

Open BanacialPC2 opened 2 weeks ago

BanacialPC2 commented 2 weeks ago

Needed this for

var hr = self.enumerator.?.IMMDeviceEnumerator_GetDefaultAudioEndpoint(...)

where mmdeviceapi defines:

#define E_NOTFOUND HRESULT_FROM_WIN32(ERROR_NOT_FOUND)

which is not the same as

// here pub const E_NOTFOUND = @import("../zig.zig").typedConst(HRESULT, @as(i32, -2147479539));
// but should be  = @import("../zig.zig").typedConst(HRESULT, @as(i32, -2147023728));
// perhabs different  E_NOTFOUND ' s ???
pub const E_NOTFOUND = @import("../win32.zig").data.html_help.E_NOTFOUND;

Adding 2.1.2 HRESULT From WIN32 Error Code Macro -> Learn\2.1.2 HRESULT From WIN32 Error Code Macro https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/0c0bcf55-277e-4120-b5dc-f6115fc8dc38

Needed this for:

            var hr = self.enumerator.?.IMMDeviceEnumerator_GetDefaultAudioEndpoint(win32.eRender, win32.eConsole, &default_playback_device); 
            defer _ = default_playback_device.?.IUnknown_Release();
            switch (hr) {
                win32.S_OK => {},
                win32.E_POINTER => unreachable,
                win32.E_INVALIDARG => unreachable,
                win32.E_OUTOFMEMORY => return error.OutOfMemory,
                // Here -> 
                win32_utils.HRESULT_FROM_WIN32(win32.ERROR_NOT_FOUND) => break :blk null,
                else => return error.OpeningDevice,
            }