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

Add "vtbl" option for low-level interface vtable generation #2845

Merged
merged 6 commits into from
Feb 14, 2024
Merged

Conversation

kennykerr
Copy link
Collaborator

The windows-bindgen crate's "sys" config option avoids generating bindings for COM interfaces since those necessarily require function bodies to implement virtual function calls, not directly supported by Rust. The "sys"-style bindings avoid generating function bodies to reduce build time.

However in some rare cases, it can be useful to have the ability to call COM interfaces without having to manually define them all from scratch or generating full-blown COM interface support. This update introduces the "vtbl" option as a middle ground that may be used along with the "sys" option and will instruct the windows-bindgen crate to generate the IID and vtable layouts as follows:

pub const IID_IStringable: GUID = GUID::from_u128(0x96369f54_8eb6_48f0_abce_c1b211e627c3);

#[repr(C)]
pub struct IStringable_Vtbl {
    pub base__: IInspectable_Vtbl,
    pub ToString: unsafe extern "system" fn(*mut ::core::ffi::c_void, *mut *mut ::core::ffi::c_void) -> HRESULT,
}

No functions are added, and you still have to go to the trouble of dereferncing a COM interface pointer, but at least the virtual function signatures are available for you to do so.

This is only available through the "vtbl" config option and does not affect the windows or windows-sys crates.

@kennykerr kennykerr merged commit a86c71a into master Feb 14, 2024
65 checks passed
@kennykerr kennykerr deleted the vtbl branch February 14, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant