Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

[Help] Using IOleObject interface #162

Closed
konghk78 opened this issue Aug 7, 2020 · 2 comments
Closed

[Help] Using IOleObject interface #162

konghk78 opened this issue Aug 7, 2020 · 2 comments
Labels
question Further information is requested

Comments

@konghk78
Copy link

konghk78 commented Aug 7, 2020

Hello,

Currently, I'm trying to use IOleObject interface.
To fulfill the interface, it seems like I should provide IOleClientSite implementation via SetClientSite.

#[uuid("00000118-0000-0000-C000-000000000046")]
pub unsafe interface IOleClientSite: IUnknown {
    pub unsafe fn save_object(&self) -> HRESULT;
    pub unsafe fn get_moniker(&self) -> HRESULT;
    pub unsafe fn get_container(&self) -> HRESULT;
    pub unsafe fn show_object(&self) -> HRESULT;
    pub unsafe fn on_show_window(&self) -> HRESULT;
    pub unsafe fn request_new_object_layout(&self) -> HRESULT;
}

#[uuid("00000112-0000-0000-C000-000000000046")]
pub unsafe interface IOleObject: IUnknown {
    pub unsafe fn set_client_site(&self, **ole_clinet_site: IOleClientSite**) -> HRESULT; //required
    pub unsafe fn get_client_site(
        &self,
        ole_clinet_site: IOleClientSite,
    ) -> HRESULT;

    // skip

    pub unsafe fn enum_advise(&self) -> HRESULT;
    pub unsafe fn get_misc_status(&self, dw_aspect: INT, dw_status: *mut INT) -> HRESULT; //required
    pub unsafe fn set_color_scheme(&self) -> HRESULT;
}

I tried to use class! macro to implement IOleClientSite interface.
I couldn't find a way to use OleClientSite class as an input of set_client_site.
I'm new to both rust and com, so any comment would be appreciated.

class! {
    pub class OleClientSite: IOleClientSite {
    }

    impl IOleClientSite for OleClientSite {
        unsafe fn save_object(&self) -> HRESULT
        {
            let result:HRESULT = 0;
            result
        }
        unsafe fn get_moniker(&self) -> HRESULT
        {
            let result:HRESULT = 0;
            result
        }
        unsafe fn get_container(&self) -> HRESULT
        {
            let result:HRESULT = 0;
            result
        }
        unsafe fn show_object(&self) -> HRESULT
        {
            let result:HRESULT = 0;
            result
        }
        unsafe fn on_show_window(&self) -> HRESULT
        {
            let result:HRESULT = 0;
            result
        }
        unsafe fn request_new_object_layout(&self) -> HRESULT
        {
            let result:HRESULT = 0;
            result
        }
    }
}

impl Default for OleClientSite {
    // Required for com-rs, even if we never want it to create an instance for us.
    fn default() -> Self {
        OleClientSite::new()
    }
}
@konghk78 konghk78 changed the title Using IOleObject interface [Help] Using IOleObject interface Aug 7, 2020
@rylev rylev added the question Further information is requested label Aug 12, 2020
@rylev
Copy link
Contributor

rylev commented Aug 12, 2020

I'm not familiar at all with Ole so I hope I can help.

You'll need the changes in #163 for this to work. The signature of set_client_site should be:

pub unsafe fn set_client_site(&self, client_site: IOleClientSite) -> HRESULT;

if you want to set your OleClientSite class then you need to first create and allocate one:

// assumes you already have a handle to an `IOleObject` in an `ole_object` variable
let client_site = OleClientSite::alloc::<IOleClientSite>(OleClientSite::default()).expect("Could not get OleClientSite class as an IOleClientSite");
ole_object.set_client_site(client_site);

@konghk78
Copy link
Author

Thanks a lot for the answer!

@rylev rylev closed this as completed Aug 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants