microsoft / win32metadata

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

It would be nice to have an `impl From<DEVPROPKEY> for PROPERTYKEY` #1922

Closed docwilco closed 9 hours ago

docwilco commented 2 months ago

Suggestion

When getting properties for a device, all the constants (like Properties::DEVPKEY_Device_FriendlyName) are of type DEVPROPKEY, but IPropertyStore::GetValue() takes a *const PROPERTYKEY.

I guess having IPropertyStore::GetValue() take an Into<PROPERTYKEY> of some form would be nice as well :)

As a workaround, I'm currently using:

static DEVICE_FRIENDLY_NAME: PROPERTYKEY = PROPERTYKEY {
    fmtid: Properties::DEVPKEY_Device_FriendlyName.fmtid,
    pid: Properties::DEVPKEY_Device_FriendlyName.pid,
};
kennykerr commented 2 months ago

This seems like a question/issue for metadata to address. If these structs are interchangeable, perhaps they should be folded into a single struct. Anyway, will transfer for their consideration.

mikebattista commented 9 hours ago

I moved DEVPROPKEY and PROPERTYKEY to Windows.Win32.Foundation and added AlsoUsableFor("PROPERTYKEY") to DEVPROPKEY which should allow you to pass DEVPROPKEYs wherever PROPERTYKEYs are expected.