microsoft / win32metadata

Tooling to generate metadata for Win32 APIs in the Windows SDK.
Other
1.32k stars 113 forks source link

Have `GetClassNameW` return `Result<i32>` if possible #1944

Closed Zerowalker closed 1 week ago

Zerowalker commented 1 month ago

Suggestion

According to the docs: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclassnamew

If the function succeeds, the return value is the number of characters copied to the buffer, not including the terminating null character.

If the function fails, the return value is zero. To get extended error information, call [GetLastError](https://learn.microsoft.com/en-us/windows/desktop/api/errhandlingapi/nf-errhandlingapi-getlasterror).

Which means it should basically work like this:

        let mut buf = [0u16; 256];
        match unsafe { GetClassNameW(hwnd, &mut buf) }{
            0=> Err(windows::core::Error::from_win32()),
            o =>Ok(o)
        }

Not sure if the Meta supports this, but just throwing this suggestion in there

kennykerr commented 1 month ago

This is more of a limitation of metadata unfortunately. Since the function returns a primitive type, there's no real way to annotate it with the necessary information about what values might be invalid and thus map to an error. Ideally this would be attributed on the function itself, but the Win32 metadata chose to attribute this on the return type like HANDLE, HRGN, and so on.

mominshaikhdevs commented 1 month ago

why not transfer this issue to the win32metadata repo?

kennykerr commented 1 month ago

Sure, I can transfer it for you.

mikebattista commented 1 week ago

What's the suggested change?

kennykerr commented 1 week ago

I don't believe there is a change that would make a practical difference here.