4 releases

0.1.3 Mar 17, 2024
0.1.2 Mar 10, 2024
0.1.1 Mar 10, 2024
0.1.0 Mar 10, 2024

#17 in #com-interface

Download history 12/week @ 2024-07-05 1/week @ 2024-07-26

150 downloads per month
Used in wvwasi

MIT/Apache

18KB
216 lines

Macros for the wvwasi crate.

wvwasi_macro::create_type_info_crate

Create a trait with a method called create_disp_type_info. The create_disp_type_info method returns an ITypeInfo for the following trait.

Example

#[wvwasi_macro::create_type_info_crate(ISyncIPCHandler_TypeInfo)]
#[windows::core::interface("094d70d6-5202-44b8-abb8-43860da5aca2")]
unsafe trait ISyncIPCHandler: windows::core::IUnknown {
  unsafe fn test(&self, message: windows::core::BSTR) -> windows::core::BSTR;
  unsafe fn test2(&self) -> u16;
}

#[windows::core::implement(windows::Win32::System::Com::IDispatch, ISyncIPCHandler)]
struct SyncIPCHandler {
  type_info: ITypeInfo,
}

impl ISyncIPCHandler_TypeInfo for SyncIPCHandler {}
impl ISyncIPCHandler_Impl for SyncIPCHandler {
  unsafe fn test(&self, message: windows::core::BSTR) {
    windows::core::BSTR::default()
  }
  unsafe fn test2(&self) -> u16 {
    123u16
  }
}
impl IDispatch_Impl for SyncIPCHandler {
  fn GetTypeInfoCount(&self) -> windows::core::Result<u32> {
    Ok(1)
  }
  fn GetTypeInfo(&self, itinfo: u32, _lcid: u32) -> windows::core::Result<ITypeInfo> {
    if itinfo != 0 {
      Err(windows::Win32::Foundation::DISP_E_BADINDEX.into())
    } else {
      Ok(self.type_info.clone())
    }
  }
  fn GetIDsOfNames(
    &self,
    riid: *const windows::core::GUID,
    rgsznames: *const windows::core::PCWSTR,
    cnames: u32,
    _lcid: u32,
    rgdispid: *mut i32,
  ) -> windows::core::Result<()> {
    unsafe {
      if riid.is_null() || *riid != windows::core::GUID::default() {
        Err(windows::Win32::Foundation::DISP_E_UNKNOWNINTERFACE.into())
      } else {
        windows::Win32::System::Ole::DispGetIDsOfNames(&self.type_info, rgsznames, cnames, rgdispid)
      }
    }
  }
  fn Invoke(
    &self,
    dispidmember: i32,
    riid: *const windows::core::GUID,
    _lcid: u32,
    wflags: DISPATCH_FLAGS,
    pdispparams: *const DISPPARAMS,
    pvarresult: *mut VARIANT,
    pexcepinfo: *mut EXCEPINFO,
    puargerr: *mut u32,
  ) -> windows::core::Result<()> {
    unsafe {
      if riid.is_null() || *riid != windows::core::GUID::default() {
        Err(windows::Win32::Foundation::DISP_E_UNKNOWNINTERFACE.into())
      } else {
        let this: ISyncIPCHandler = self.cast()?;
    
        let mut dispparams = if pdispparams.is_null() {
          None
        } else {
          Some(*pdispparams)
        };
        let pdispparams_mut = dispparams
          .as_mut()
          .map(|x| x as _)
          .unwrap_or(std::ptr::null_mut());
    
        windows::Win32::System::Ole::DispInvoke(
          windows::core::Interface::as_raw(&this),
          &self.type_info,
          dispidmember,
          wflags.0,
          pdispparams_mut,
          pvarresult,
          pexcepinfo,
          puargerr,
        )
      }
    }
  }
}

fn main() {
  let type_info = SyncIPCHandler::create_disp_type_info();
  let host_object = SyncIPCHandler { type_info };
}

Dependencies

~127MB
~2M SLoC