wvwasi-macro

Crates.iowvwasi-macro
lib.rswvwasi-macro
version0.1.3
sourcesrc
created_at2024-03-10 14:39:15.302601
updated_at2024-03-17 11:43:02.137996
descriptionMacros for the wvwasi crate.
homepagehttps://wvwasi.com
repositoryhttps://github.com/defims/wvwasi
max_upload_size
id1168732
size17,732
Wei Long (defims)

documentation

README

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 };
}
Commit count: 9

cargo fmt