Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/libs/core/src/guid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ pub struct GUID {
impl GUID {
/// Creates a unique `GUID` value.
pub fn new() -> Result<Self> {
unsafe { imp::CoCreateGuid() }
let mut guid = Self::zeroed();
let result = unsafe { imp::UuidCreate(&mut guid as *mut _ as _) };

if matches!(result, 0 | imp::RPC_S_UUID_LOCAL_ONLY) {
Ok(guid)
} else {
Err(Error::from_hresult(HRESULT::from_win32(result as u32)))
}
}

/// Creates a `GUID` represented by the all-zero byte-pattern.
Expand Down
3 changes: 3 additions & 0 deletions crates/libs/core/src/imp/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ windows_link::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : HMODULE)
windows_link::link!("kernel32.dll" "system" fn GetProcAddress(hmodule : HMODULE, lpprocname : PCSTR) -> FARPROC);
windows_link::link!("kernel32.dll" "system" fn LoadLibraryExA(lplibfilename : PCSTR, hfile : HANDLE, dwflags : LOAD_LIBRARY_FLAGS) -> HMODULE);
windows_link::link!("api-ms-win-core-winrt-l1-1-0.dll" "system" fn RoGetActivationFactory(activatableclassid : HSTRING, iid : *const GUID, factory : *mut *mut core::ffi::c_void) -> HRESULT);
windows_link::link!("rpcrt4.dll" "system" fn UuidCreate(uuid : *mut GUID) -> RPC_STATUS);
pub type BOOL = i32;
pub type CO_MTA_USAGE_COOKIE = *mut core::ffi::c_void;
pub type FARPROC = Option<unsafe extern "system" fn() -> isize>;
Expand Down Expand Up @@ -42,4 +43,6 @@ pub type HRESULT = i32;
pub type LOAD_LIBRARY_FLAGS = u32;
pub const LOAD_LIBRARY_SEARCH_DEFAULT_DIRS: LOAD_LIBRARY_FLAGS = 4096u32;
pub type PCSTR = *const u8;
pub type RPC_STATUS = i32;
pub const RPC_S_UUID_LOCAL_ONLY: RPC_STATUS = 1824i32;
pub type HSTRING = *mut core::ffi::c_void;
8 changes: 0 additions & 8 deletions crates/libs/core/src/imp/com_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
clippy::all
)]

#[inline]
pub unsafe fn CoCreateGuid() -> windows_core::Result<windows_core::GUID> {
windows_link::link!("ole32.dll" "system" fn CoCreateGuid(pguid : *mut windows_core::GUID) -> windows_core::HRESULT);
unsafe {
let mut result__ = core::mem::zeroed();
CoCreateGuid(&mut result__).map(|| result__)
}
}
#[inline]
pub unsafe fn RoGetAgileReference<P2>(
options: AgileReferenceOptions,
Expand Down
2 changes: 2 additions & 0 deletions crates/libs/core/src/imp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#[cfg(windows)]
include!("windows.rs");

mod bindings;
mod can_into;
mod com_bindings;
mod ref_count;
mod sha1;
mod weak_ref_count;

pub use bindings::*;
pub use can_into::*;
pub use com_bindings::*;
pub use ref_count::*;
Expand Down
3 changes: 0 additions & 3 deletions crates/libs/core/src/imp/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ pub use factory_cache::*;
mod generic_factory;
pub use generic_factory::*;

mod bindings;
pub use bindings::*;

mod marshaler;
pub use marshaler::*;
2 changes: 2 additions & 0 deletions crates/tools/bindings/src/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS
LoadLibraryExA
RoGetActivationFactory
RPC_S_UUID_LOCAL_ONLY
UuidCreate
1 change: 0 additions & 1 deletion crates/tools/bindings/src/core_com.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
--filter
AGILEREFERENCE_DEFAULT
CO_E_NOTINITIALIZED
CoCreateGuid
E_INVALIDARG
E_NOINTERFACE
E_POINTER
Expand Down