Crates.io | wvwasi-macro |
lib.rs | wvwasi-macro |
version | 0.1.3 |
source | src |
created_at | 2024-03-10 14:39:15.302601 |
updated_at | 2024-03-17 11:43:02.137996 |
description | Macros for the wvwasi crate. |
homepage | https://wvwasi.com |
repository | https://github.com/defims/wvwasi |
max_upload_size | |
id | 1168732 |
size | 17,732 |
Create a trait with a method called create_disp_type_info. The create_disp_type_info method returns an ITypeInfo for the following trait.
#[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 };
}