Created
January 10, 2023 17:04
-
-
Save kennykerr/080aacb05a0f2f214779118bd838f2f2 to your computer and use it in GitHub Desktop.
COM without `windows` crate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(non_snake_case)] | |
use windows_sys::{core::*, Win32::Foundation::*, Win32::System::Com::*}; | |
fn main() { | |
unsafe { | |
let mut uri = std::ptr::null_mut(); | |
let hr = CreateUri( | |
w!("http://kennykerr.ca"), | |
Uri_CREATE_CANONICALIZE, | |
0, | |
&mut uri, | |
); | |
assert!(hr == 0); | |
let uri = uri as *mut *mut IUri_Vtbl; | |
let mut domain = std::ptr::null_mut(); | |
let hr = ((**uri).GetDomain)(uri, &mut domain); | |
assert!(hr == 0); | |
let mut port = 0; | |
let hr = ((**uri).GetPort)(uri, &mut port); | |
assert!(hr == 0); | |
println!( | |
"{} ({port})", | |
String::from_utf16_lossy(std::slice::from_raw_parts( | |
domain, | |
SysStringLen(domain) as _ | |
)) | |
); | |
SysFreeString(domain); | |
((**uri).base__.Release)(uri as _); | |
} | |
} | |
#[repr(C)] | |
pub struct IUnknown_Vtbl { | |
pub QueryInterface: unsafe extern "system" fn( | |
this: *mut *mut IUnknown_Vtbl, | |
iid: &GUID, | |
interface: *mut *const std::ffi::c_void, | |
) -> HRESULT, | |
pub AddRef: unsafe extern "system" fn(this: *mut *mut IUnknown_Vtbl) -> u32, | |
pub Release: unsafe extern "system" fn(this: *mut *mut IUnknown_Vtbl) -> u32, | |
} | |
#[repr(C)] | |
pub struct IUri_Vtbl { | |
pub base__: IUnknown_Vtbl, | |
pub GetPropertyBSTR: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
uriprop: Uri_PROPERTY, | |
pbstrproperty: *mut *mut ::core::ffi::c_void, | |
dwflags: u32, | |
) -> HRESULT, | |
pub GetPropertyLength: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
uriprop: Uri_PROPERTY, | |
pcchproperty: *mut u32, | |
dwflags: u32, | |
) -> HRESULT, | |
pub GetPropertyDWORD: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
uriprop: Uri_PROPERTY, | |
pdwproperty: *mut u32, | |
dwflags: u32, | |
) -> HRESULT, | |
pub HasProperty: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
uriprop: Uri_PROPERTY, | |
pfhasproperty: *mut BOOL, | |
) -> HRESULT, | |
pub GetAbsoluteUri: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrabsoluteuri: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetAuthority: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrauthority: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetDisplayUri: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrdisplaystring: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetDomain: | |
unsafe extern "system" fn(this: *mut *mut IUri_Vtbl, pbstrdomain: *mut *mut u16) -> HRESULT, | |
pub GetExtension: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrextension: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetFragment: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrfragment: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetHost: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrhost: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetPassword: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrpassword: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetPath: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrpath: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetPathAndQuery: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrpathandquery: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetQuery: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrquery: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetRawUri: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrrawuri: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetSchemeName: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrschemename: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetUserInfo: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstruserinfo: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetUserName: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
pbstrusername: *mut *mut ::core::ffi::c_void, | |
) -> HRESULT, | |
pub GetHostType: | |
unsafe extern "system" fn(this: *mut *mut IUri_Vtbl, pdwhosttype: *mut u32) -> HRESULT, | |
pub GetPort: unsafe extern "system" fn(this: *mut *mut IUri_Vtbl, pdwport: *mut u32) -> HRESULT, | |
pub GetScheme: | |
unsafe extern "system" fn(this: *mut *mut IUri_Vtbl, pdwscheme: *mut u32) -> HRESULT, | |
pub GetZone: unsafe extern "system" fn(this: *mut *mut IUri_Vtbl, pdwzone: *mut u32) -> HRESULT, | |
pub GetProperties: | |
unsafe extern "system" fn(this: *mut *mut IUri_Vtbl, pdwflags: *mut u32) -> HRESULT, | |
pub IsEqual: unsafe extern "system" fn( | |
this: *mut *mut IUri_Vtbl, | |
puri: *mut ::core::ffi::c_void, | |
pfequal: *mut BOOL, | |
) -> HRESULT, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment