Skip to content

Commit 24490bf

Browse files
authored
Remove ole32.dll dependency from windows-core crate for compatibility (#3743)
1 parent 7ffbf24 commit 24490bf

File tree

9 files changed

+32
-19
lines changed

9 files changed

+32
-19
lines changed

crates/libs/bindgen/src/libraries.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ fn combine_libraries(
2626
continue;
2727
};
2828

29-
// Windows libs are always produced with lower case module names.
30-
let library = ty.method.module_name().to_lowercase();
29+
let library = ty.method.module_name();
3130
let impl_map = ty.method.impl_map().unwrap();
3231
let flags = impl_map.flags();
3332
let name = impl_map.import_name().to_string();

crates/libs/bindgen/src/tables/method_def.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,22 @@ impl MethodDef {
4040
.next()
4141
}
4242

43-
pub fn module_name(&self) -> &'static str {
44-
self.impl_map().map_or("", |map| map.scope().name())
43+
pub fn module_name(&self) -> String {
44+
const combase_functions: [&str; 5] = [
45+
"CoCreateFreeThreadedMarshaler",
46+
"CoIncrementMTAUsage",
47+
"CoTaskMemAlloc",
48+
"CoTaskMemFree",
49+
"RoGetAgileReference",
50+
];
51+
52+
if combase_functions.contains(&self.name()) {
53+
"combase.dll".to_string()
54+
} else {
55+
self.impl_map()
56+
.map_or("", |map| map.scope().name())
57+
.to_lowercase()
58+
}
4559
}
4660

4761
pub fn calling_convention(&self) -> &'static str {

crates/libs/bindgen/src/types/cpp_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl CppFn {
2828
}
2929

3030
pub fn write_link(&self, config: &Config, underlying_types: bool) -> TokenStream {
31-
let library = self.method.module_name().to_lowercase();
31+
let library = self.method.module_name();
3232
let symbol = self.method.import_name();
3333
let name = to_ident(self.method.name());
3434
let abi = self.method.calling_convention();

crates/libs/core/src/imp/bindings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
windows_link::link!("ole32.dll" "system" fn CoIncrementMTAUsage(pcookie : *mut CO_MTA_USAGE_COOKIE) -> HRESULT);
2-
windows_link::link!("ole32.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mut core::ffi::c_void);
3-
windows_link::link!("ole32.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
1+
windows_link::link!("combase.dll" "system" fn CoIncrementMTAUsage(pcookie : *mut CO_MTA_USAGE_COOKIE) -> HRESULT);
2+
windows_link::link!("combase.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mut core::ffi::c_void);
3+
windows_link::link!("combase.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
44
windows_link::link!("kernel32.dll" "system" fn EncodePointer(ptr : *const core::ffi::c_void) -> *mut core::ffi::c_void);
55
windows_link::link!("kernel32.dll" "system" fn FreeLibrary(hlibmodule : HMODULE) -> BOOL);
66
windows_link::link!("kernel32.dll" "system" fn GetProcAddress(hmodule : HMODULE, lpprocname : PCSTR) -> FARPROC);

crates/libs/core/src/imp/com_bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub unsafe fn RoGetAgileReference<P2>(
77
where
88
P2: windows_core::Param<windows_core::IUnknown>,
99
{
10-
windows_link::link!("ole32.dll" "system" fn RoGetAgileReference(options : AgileReferenceOptions, riid : *const windows_core::GUID, punk : * mut core::ffi::c_void, ppagilereference : *mut * mut core::ffi::c_void) -> windows_core::HRESULT);
10+
windows_link::link!("combase.dll" "system" fn RoGetAgileReference(options : AgileReferenceOptions, riid : *const windows_core::GUID, punk : * mut core::ffi::c_void, ppagilereference : *mut * mut core::ffi::c_void) -> windows_core::HRESULT);
1111
unsafe {
1212
let mut result__ = core::mem::zeroed();
1313
RoGetAgileReference(options, riid, punk.param().abi(), &mut result__)

crates/libs/core/src/imp/marshaler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::ffi::c_void;
44
use core::mem::{transmute, transmute_copy};
55
use core::ptr::null_mut;
66

7-
windows_link::link!("ole32.dll" "system" fn CoCreateFreeThreadedMarshaler(punkouter: *mut c_void, ppunkmarshal: *mut *mut c_void) -> HRESULT);
7+
windows_link::link!("combase.dll" "system" fn CoCreateFreeThreadedMarshaler(punkouter: *mut c_void, ppunkmarshal: *mut *mut c_void) -> HRESULT);
88

99
pub unsafe fn marshaler(outer: IUnknown, result: *mut *mut c_void) -> HRESULT {
1010
unsafe {

crates/libs/sys/src/Windows/Win32/System/Com/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ windows_link::link!("ole32.dll" "system" fn CoAllowUnmarshalerCLSID(clsid : *con
1414
windows_link::link!("ole32.dll" "system" fn CoBuildVersion() -> u32);
1515
windows_link::link!("ole32.dll" "system" fn CoCancelCall(dwthreadid : u32, ultimeout : u32) -> windows_sys::core::HRESULT);
1616
windows_link::link!("ole32.dll" "system" fn CoCopyProxy(pproxy : * mut core::ffi::c_void, ppcopy : *mut * mut core::ffi::c_void) -> windows_sys::core::HRESULT);
17-
windows_link::link!("ole32.dll" "system" fn CoCreateFreeThreadedMarshaler(punkouter : * mut core::ffi::c_void, ppunkmarshal : *mut * mut core::ffi::c_void) -> windows_sys::core::HRESULT);
17+
windows_link::link!("combase.dll" "system" fn CoCreateFreeThreadedMarshaler(punkouter : * mut core::ffi::c_void, ppunkmarshal : *mut * mut core::ffi::c_void) -> windows_sys::core::HRESULT);
1818
windows_link::link!("ole32.dll" "system" fn CoCreateGuid(pguid : *mut windows_sys::core::GUID) -> windows_sys::core::HRESULT);
1919
windows_link::link!("ole32.dll" "system" fn CoCreateInstance(rclsid : *const windows_sys::core::GUID, punkouter : * mut core::ffi::c_void, dwclscontext : CLSCTX, riid : *const windows_sys::core::GUID, ppv : *mut *mut core::ffi::c_void) -> windows_sys::core::HRESULT);
2020
windows_link::link!("ole32.dll" "system" fn CoCreateInstanceEx(clsid : *const windows_sys::core::GUID, punkouter : * mut core::ffi::c_void, dwclsctx : CLSCTX, pserverinfo : *const COSERVERINFO, dwcount : u32, presults : *mut MULTI_QI) -> windows_sys::core::HRESULT);
@@ -47,7 +47,7 @@ windows_link::link!("ole32.dll" "system" fn CoGetPSClsid(riid : *const windows_s
4747
windows_link::link!("ole32.dll" "system" fn CoGetSystemSecurityPermissions(comsdtype : COMSD, ppsd : *mut super::super::Security:: PSECURITY_DESCRIPTOR) -> windows_sys::core::HRESULT);
4848
windows_link::link!("ole32.dll" "system" fn CoGetTreatAsClass(clsidold : *const windows_sys::core::GUID, pclsidnew : *mut windows_sys::core::GUID) -> windows_sys::core::HRESULT);
4949
windows_link::link!("ole32.dll" "system" fn CoImpersonateClient() -> windows_sys::core::HRESULT);
50-
windows_link::link!("ole32.dll" "system" fn CoIncrementMTAUsage(pcookie : *mut CO_MTA_USAGE_COOKIE) -> windows_sys::core::HRESULT);
50+
windows_link::link!("combase.dll" "system" fn CoIncrementMTAUsage(pcookie : *mut CO_MTA_USAGE_COOKIE) -> windows_sys::core::HRESULT);
5151
windows_link::link!("ole32.dll" "system" fn CoInitialize(pvreserved : *const core::ffi::c_void) -> windows_sys::core::HRESULT);
5252
windows_link::link!("ole32.dll" "system" fn CoInitializeEx(pvreserved : *const core::ffi::c_void, dwcoinit : u32) -> windows_sys::core::HRESULT);
5353
#[cfg(feature = "Win32_Security")]
@@ -80,8 +80,8 @@ windows_link::link!("ole32.dll" "system" fn CoSetCancelObject(punk : * mut core:
8080
windows_link::link!("ole32.dll" "system" fn CoSetProxyBlanket(pproxy : * mut core::ffi::c_void, dwauthnsvc : u32, dwauthzsvc : u32, pserverprincname : windows_sys::core::PCWSTR, dwauthnlevel : RPC_C_AUTHN_LEVEL, dwimplevel : RPC_C_IMP_LEVEL, pauthinfo : *const core::ffi::c_void, dwcapabilities : u32) -> windows_sys::core::HRESULT);
8181
windows_link::link!("ole32.dll" "system" fn CoSuspendClassObjects() -> windows_sys::core::HRESULT);
8282
windows_link::link!("ole32.dll" "system" fn CoSwitchCallContext(pnewobject : * mut core::ffi::c_void, ppoldobject : *mut * mut core::ffi::c_void) -> windows_sys::core::HRESULT);
83-
windows_link::link!("ole32.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mut core::ffi::c_void);
84-
windows_link::link!("ole32.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
83+
windows_link::link!("combase.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mut core::ffi::c_void);
84+
windows_link::link!("combase.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
8585
windows_link::link!("ole32.dll" "system" fn CoTaskMemRealloc(pv : *const core::ffi::c_void, cb : usize) -> *mut core::ffi::c_void);
8686
windows_link::link!("ole32.dll" "system" fn CoTestCancel() -> windows_sys::core::HRESULT);
8787
windows_link::link!("ole32.dll" "system" fn CoTreatAsClass(clsidold : *const windows_sys::core::GUID, clsidnew : *const windows_sys::core::GUID) -> windows_sys::core::HRESULT);

crates/libs/windows/src/Windows/Win32/System/Com/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub unsafe fn CoCreateFreeThreadedMarshaler<P0>(punkouter: P0) -> windows_core::
9999
where
100100
P0: windows_core::Param<windows_core::IUnknown>,
101101
{
102-
windows_link::link!("ole32.dll" "system" fn CoCreateFreeThreadedMarshaler(punkouter : * mut core::ffi::c_void, ppunkmarshal : *mut * mut core::ffi::c_void) -> windows_core::HRESULT);
102+
windows_link::link!("combase.dll" "system" fn CoCreateFreeThreadedMarshaler(punkouter : * mut core::ffi::c_void, ppunkmarshal : *mut * mut core::ffi::c_void) -> windows_core::HRESULT);
103103
unsafe {
104104
let mut result__ = core::mem::zeroed();
105105
CoCreateFreeThreadedMarshaler(punkouter.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__))
@@ -319,7 +319,7 @@ pub unsafe fn CoImpersonateClient() -> windows_core::Result<()> {
319319
}
320320
#[inline]
321321
pub unsafe fn CoIncrementMTAUsage() -> windows_core::Result<CO_MTA_USAGE_COOKIE> {
322-
windows_link::link!("ole32.dll" "system" fn CoIncrementMTAUsage(pcookie : *mut CO_MTA_USAGE_COOKIE) -> windows_core::HRESULT);
322+
windows_link::link!("combase.dll" "system" fn CoIncrementMTAUsage(pcookie : *mut CO_MTA_USAGE_COOKIE) -> windows_core::HRESULT);
323323
unsafe {
324324
let mut result__ = core::mem::zeroed();
325325
CoIncrementMTAUsage(&mut result__).map(|| result__)
@@ -545,12 +545,12 @@ where
545545
}
546546
#[inline]
547547
pub unsafe fn CoTaskMemAlloc(cb: usize) -> *mut core::ffi::c_void {
548-
windows_link::link!("ole32.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mut core::ffi::c_void);
548+
windows_link::link!("combase.dll" "system" fn CoTaskMemAlloc(cb : usize) -> *mut core::ffi::c_void);
549549
unsafe { CoTaskMemAlloc(cb) }
550550
}
551551
#[inline]
552552
pub unsafe fn CoTaskMemFree(pv: Option<*const core::ffi::c_void>) {
553-
windows_link::link!("ole32.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
553+
windows_link::link!("combase.dll" "system" fn CoTaskMemFree(pv : *const core::ffi::c_void));
554554
unsafe { CoTaskMemFree(pv.unwrap_or(core::mem::zeroed()) as _) }
555555
}
556556
#[inline]

crates/libs/windows/src/Windows/Win32/System/WinRT/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub unsafe fn RoGetAgileReference<P2>(options: AgileReferenceOptions, riid: *con
185185
where
186186
P2: windows_core::Param<windows_core::IUnknown>,
187187
{
188-
windows_link::link!("ole32.dll" "system" fn RoGetAgileReference(options : AgileReferenceOptions, riid : *const windows_core::GUID, punk : * mut core::ffi::c_void, ppagilereference : *mut * mut core::ffi::c_void) -> windows_core::HRESULT);
188+
windows_link::link!("combase.dll" "system" fn RoGetAgileReference(options : AgileReferenceOptions, riid : *const windows_core::GUID, punk : * mut core::ffi::c_void, ppagilereference : *mut * mut core::ffi::c_void) -> windows_core::HRESULT);
189189
unsafe {
190190
let mut result__ = core::mem::zeroed();
191191
RoGetAgileReference(options, riid, punk.param().abi(), &mut result__).and_then(|| windows_core::Type::from_abi(result__))

0 commit comments

Comments
 (0)