Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IEnumWbemClassObject::Next hard to use #1266

Closed
kennykerr opened this issue Sep 20, 2022 · 4 comments
Closed

IEnumWbemClassObject::Next hard to use #1266

kennykerr opened this issue Sep 20, 2022 · 4 comments
Assignees
Labels
rust Critical for Rust adoption

Comments

@kennykerr
Copy link
Contributor

The first parameter is a timeout that you can use for an arbitrary timeout, or you can pass either WBEM_NO_WAIT or WBEM_INFINITE. Unfortunately, those constants are grouped into an enum, making it hard to pass directly to this function which expects an integer. These constants should just be loose integer constants rather than an enum.

@kennykerr kennykerr added the rust Critical for Rust adoption label Sep 20, 2022
@mikebattista mikebattista self-assigned this Sep 21, 2022
@mikebattista
Copy link
Collaborator

This enum is coming from the headers as is, and it looks like the enum is typed as int already, as is the timeout parameter of the API. What's making it hard to pass? Do you need to cast the enum value to int?

@kennykerr
Copy link
Contributor Author

The constants WBEM_NO_WAIT and WBEM_INFINITE are typed WBEM_TIMEOUT_TYPE so any language that doesn't provide implicit conversions to the underlying type (int) will require an additional cast to call Next to be called with these constants.

I should be able to say Next(123, ...) or Next(WBEM_INFINITE, ...) but as it is I have to "unpack" the value behind the constant and say Next(WBEM_INFINITE.0, ...) in Rust or in C++ you'd have to say Next(static_cast<int>(WBEM_NO_WAIT), ...).

But if those two constants were typed int, which is what the API expects, then it would "just work" without requiring a cast.

The confusion may come from the fact that they're declared as old-fashioned C-style enums which are nothing more than global constants, rather than C++-style enums which are scoped.

@mikebattista
Copy link
Collaborator

Ok. We can exclude the enum from the header and declare the constants manually.

@mikebattista
Copy link
Collaborator

Windows.Win32.System.Wmi.WBEM_TIMEOUT_TYPE removed
Windows.Win32.System.Wmi.WBEM_TIMEOUT_TYPE.WBEM_INFINITE removed
Windows.Win32.System.Wmi.WBEM_TIMEOUT_TYPE.WBEM_NO_WAIT removed
Windows.Win32.System.Wmi.Apis.WBEM_INFINITE added
Windows.Win32.System.Wmi.Apis.WBEM_NO_WAIT added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Critical for Rust adoption
Projects
None yet
Development

No branches or pull requests

2 participants