Skip to content

Commit cf11d35

Browse files
committed
Use extern "C" instead of extern "cdecl"
1 parent 1c1e563 commit cf11d35

File tree

10 files changed

+24
-11
lines changed

10 files changed

+24
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl MethodDef {
5151
if flags.contains(PInvokeAttributes::CallConvPlatformapi) {
5252
"system"
5353
} else if flags.contains(PInvokeAttributes::CallConvCdecl) {
54-
"cdecl"
54+
"C"
5555
} else {
5656
""
5757
}

crates/libs/link/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! link {
3232
#[macro_export]
3333
macro_rules! link {
3434
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
35-
extern $abi {
35+
extern "C" {
3636
pub fn $($function)*;
3737
}
3838
)

crates/libs/metadata/src/reader/tables/method_def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'a> MethodDef<'a> {
4747
if flags.contains(PInvokeAttributes::CallConvPlatformapi) {
4848
"system"
4949
} else if flags.contains(PInvokeAttributes::CallConvCdecl) {
50-
"cdecl"
50+
"C"
5151
} else {
5252
""
5353
}

crates/libs/targets/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ macro_rules! link {
2828
}
2929

3030
/// Defines an external function to import.
31-
#[cfg(all(windows, not(windows_raw_dylib)))]
31+
#[cfg(all(windows, not(windows_raw_dylib), target_arch = "x86"))]
3232
#[macro_export]
3333
macro_rules! link {
3434
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
@@ -40,12 +40,25 @@ macro_rules! link {
4040
)
4141
}
4242

43+
/// Defines an external function to import.
44+
#[cfg(all(windows, not(windows_raw_dylib), not(target_arch = "x86")))]
45+
#[macro_export]
46+
macro_rules! link {
47+
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
48+
#[link(name = "windows.0.53.0")]
49+
extern "C" {
50+
$(#[link_name=$link_name])?
51+
pub fn $($function)*;
52+
}
53+
)
54+
}
55+
4356
/// Defines an external function to import.
4457
#[cfg(all(not(windows), not(windows_raw_dylib)))]
4558
#[macro_export]
4659
macro_rules! link {
4760
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => (
48-
extern $abi {
61+
extern "C" {
4962
pub fn $($function)*;
5063
}
5164
)

crates/samples/windows-sys/delay_load/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() {
3737
}
3838
}
3939

40-
type ShellMessageBoxW = unsafe extern "cdecl" fn(
40+
type ShellMessageBoxW = unsafe extern "C" fn(
4141
happinst: usize,
4242
hwnd: usize,
4343
lpctext: PCWSTR,

crates/samples/windows/delay_load/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() {
3333
}
3434
}
3535

36-
type ShellMessageBoxW = unsafe extern "cdecl" fn(
36+
type ShellMessageBoxW = unsafe extern "C" fn(
3737
happinst: usize,
3838
hwnd: usize,
3939
lpctext: PCWSTR,

crates/tests/libs/link/tests/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn link_name() {
2222

2323
#[test]
2424
fn cdecl() {
25-
windows_link::link!("wldap32.dll" "cdecl" fn LdapMapErrorToWin32(code : i32) -> u32);
25+
windows_link::link!("wldap32.dll" "C" fn LdapMapErrorToWin32(code : i32) -> u32);
2626
const LDAP_BUSY: i32 = 51;
2727
const ERROR_BUSY: u32 = 170;
2828

crates/tests/libs/targets/tests/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn link_name() {
2222

2323
#[test]
2424
fn cdecl() {
25-
windows_targets::link!("wldap32.dll" "cdecl" fn LdapMapErrorToWin32(code : i32) -> u32);
25+
windows_targets::link!("wldap32.dll" "C" fn LdapMapErrorToWin32(code : i32) -> u32);
2626
const LDAP_BUSY: i32 = 51;
2727
const ERROR_BUSY: u32 = 170;
2828

crates/tests/misc/standalone/src/b_std.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ windows_link::link!("kernel32.dll" "system" fn CloseHandle(hobject : HANDLE) ->
1010
windows_link::link!("kernel32.dll" "system" fn GetLastError() -> WIN32_ERROR);
1111
windows_link::link!("advapi32.dll" "system" "SystemFunction036" fn RtlGenRandom(randombuffer : *mut core::ffi::c_void, randombufferlength : u32) -> bool);
1212
windows_link::link!("ws2_32.dll" "system" fn socket(af : i32, r#type : WINSOCK_SOCKET_TYPE, protocol : i32) -> SOCKET);
13-
windows_link::link!("user32.dll" "cdecl" fn wsprintfA(param0 : PSTR, param1 : PCSTR, ...) -> i32);
13+
windows_link::link!("user32.dll" "C" fn wsprintfA(param0 : PSTR, param1 : PCSTR, ...) -> i32);
1414
pub type BCRYPT_ALG_HANDLE = *mut core::ffi::c_void;
1515
pub type BCRYPT_HANDLE = *mut core::ffi::c_void;
1616
pub type BOOL = i32;

crates/tests/misc/standalone/src/b_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ windows_link::link!("ole32.dll" "system" fn CoCreateInstance(rclsid : *const GUI
1111
windows_link::link!("kernel32.dll" "system" fn CreateEventW(lpeventattributes : *const SECURITY_ATTRIBUTES, bmanualreset : BOOL, binitialstate : BOOL, lpname : PCWSTR) -> HANDLE);
1212
windows_link::link!("kernel32.dll" "system" fn SetEvent(hevent : HANDLE) -> BOOL);
1313
windows_link::link!("kernel32.dll" "system" fn WaitForSingleObject(hhandle : HANDLE, dwmilliseconds : u32) -> WAIT_EVENT);
14-
windows_link::link!("user32.dll" "cdecl" fn wsprintfA(param0 : PSTR, param1 : PCSTR, ...) -> i32);
14+
windows_link::link!("user32.dll" "C" fn wsprintfA(param0 : PSTR, param1 : PCSTR, ...) -> i32);
1515
pub type BOOL = i32;
1616
pub type CLSCTX = u32;
1717
pub const CLSCTX_ALL: CLSCTX = 23u32;

0 commit comments

Comments
 (0)