From 841542cec94fc4a1073f784763a047a72b3780a0 Mon Sep 17 00:00:00 2001 From: sn99 Date: Mon, 12 Sep 2022 20:09:28 +0530 Subject: [PATCH 1/3] Migrate from winapi to windows-rs --- Cargo.toml | 6 ++-- examples/windows_guid.rs | 78 +++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8747f611..b862090c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -164,9 +164,9 @@ version = "1.0.52" [dev-dependencies.rustversion] version = "1" -[target.'cfg(windows)'.dev-dependencies.winapi] -version = "0.3" -features = ["combaseapi", "impl-default"] +[target.'cfg(windows)'.dev-dependencies.windows] +version = "0.39.0" +features = ["Win32_System_Com"] [workspace] members = [ diff --git a/examples/windows_guid.rs b/examples/windows_guid.rs index 33404b1b..abaa4bfe 100644 --- a/examples/windows_guid.rs +++ b/examples/windows_guid.rs @@ -11,35 +11,35 @@ #[cfg(windows)] fn guid_to_uuid() { use uuid::Uuid; - use winapi::shared::guiddef; + use windows::core; - let guid_in = guiddef::GUID { - Data1: 0x4a35229d, - Data2: 0x5527, - Data3: 0x4f30, - Data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], + let guid_in = core::GUID{ + data1: 0x4a35229d, + data2: 0x5527, + data3: 0x4f30, + data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], }; - let uuid = Uuid::from_fields(guid_in.Data1, guid_in.Data2, guid_in.Data3, &guid_in.Data4); + let uuid = Uuid::from_fields(guid_in.data1, guid_in.data2, guid_in.data3, &guid_in.data4); let guid_out = { let fields = uuid.as_fields(); - guiddef::GUID { - Data1: fields.0, - Data2: fields.1, - Data3: fields.2, - Data4: *fields.3, + core::GUID { + data1: fields.0, + data2: fields.1, + data3: fields.2, + data4: *fields.3, } }; assert_eq!( - (guid_in.Data1, guid_in.Data2, guid_in.Data3, guid_in.Data4), + (guid_in.data1, guid_in.data2, guid_in.data3, guid_in.data4), ( - guid_out.Data1, - guid_out.Data2, - guid_out.Data3, - guid_out.Data4 + guid_out.data1, + guid_out.data2, + guid_out.data3, + guid_out.data4 ) ); } @@ -48,39 +48,39 @@ fn guid_to_uuid() { #[cfg(windows)] fn guid_to_uuid_le_encoded() { use uuid::Uuid; - use winapi::shared::guiddef; + use windows::core; // A GUID might not be encoded directly as a UUID // If its fields are stored in little-endian order they might // need to be flipped. Whether or not this is necessary depends // on the source of the GUID - let guid_in = guiddef::GUID { - Data1: 0x9d22354a, - Data2: 0x2755, - Data3: 0x304f, - Data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], + let guid_in = core::GUID { + data1: 0x9d22354a, + data2: 0x2755, + data3: 0x304f, + data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], }; - let uuid = Uuid::from_fields_le(guid_in.Data1, guid_in.Data2, guid_in.Data3, &guid_in.Data4); + let uuid = Uuid::from_fields_le(guid_in.data1, guid_in.data2, guid_in.data3, &guid_in.data4); let guid_out = { let fields = uuid.to_fields_le(); - guiddef::GUID { - Data1: fields.0, - Data2: fields.1, - Data3: fields.2, - Data4: *fields.3, + core::GUID { + data1: fields.0, + data2: fields.1, + data3: fields.2, + data4: *fields.3, } }; assert_eq!( - (guid_in.Data1, guid_in.Data2, guid_in.Data3, guid_in.Data4), + (guid_in.data1, guid_in.data2, guid_in.data3, guid_in.data4), ( - guid_out.Data1, - guid_out.Data2, - guid_out.Data3, - guid_out.Data4 + guid_out.data1, + guid_out.data2, + guid_out.data3, + guid_out.data4 ) ); } @@ -89,15 +89,11 @@ fn guid_to_uuid_le_encoded() { #[cfg(windows)] fn uuid_from_cocreateguid() { use uuid::{Uuid, Variant, Version}; - use winapi::{shared::guiddef, um::combaseapi::CoCreateGuid}; + use windows::Win32::System::Com::CoCreateGuid; - let mut guid = guiddef::GUID::default(); + let guid = unsafe { CoCreateGuid().expect("Unable to CoCreateGuid") }; - unsafe { - CoCreateGuid(&mut guid as *mut _); - } - - let uuid = Uuid::from_fields(guid.Data1, guid.Data2, guid.Data3, &guid.Data4); + let uuid = Uuid::from_fields(guid.data1, guid.data2, guid.data3, &guid.data4); assert_eq!(Variant::RFC4122, uuid.get_variant()); assert_eq!(Some(Version::Random), uuid.get_version()); From e88af73228324a91e380064e7ddeb0e3d2865d4d Mon Sep 17 00:00:00 2001 From: sn99 Date: Fri, 23 Sep 2022 12:33:33 +0530 Subject: [PATCH 2/3] Migrate from winapi to windows-sys --- Cargo.toml | 4 ++-- examples/windows_guid.rs | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b862090c..303ad3dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -164,8 +164,8 @@ version = "1.0.52" [dev-dependencies.rustversion] version = "1" -[target.'cfg(windows)'.dev-dependencies.windows] -version = "0.39.0" +[target.'cfg(windows)'.dev-dependencies.windows-sys] +version = "0.36.1" features = ["Win32_System_Com"] [workspace] diff --git a/examples/windows_guid.rs b/examples/windows_guid.rs index abaa4bfe..320f7a3b 100644 --- a/examples/windows_guid.rs +++ b/examples/windows_guid.rs @@ -11,9 +11,9 @@ #[cfg(windows)] fn guid_to_uuid() { use uuid::Uuid; - use windows::core; + use windows_sys::core; - let guid_in = core::GUID{ + let guid_in = core::GUID { data1: 0x4a35229d, data2: 0x5527, data3: 0x4f30, @@ -48,7 +48,7 @@ fn guid_to_uuid() { #[cfg(windows)] fn guid_to_uuid_le_encoded() { use uuid::Uuid; - use windows::core; + use windows_sys::core; // A GUID might not be encoded directly as a UUID // If its fields are stored in little-endian order they might @@ -89,9 +89,17 @@ fn guid_to_uuid_le_encoded() { #[cfg(windows)] fn uuid_from_cocreateguid() { use uuid::{Uuid, Variant, Version}; - use windows::Win32::System::Com::CoCreateGuid; + use windows_sys::core; + use windows_sys::Win32::System::Com::CoCreateGuid; + + let mut guid = core::GUID { + data1: 0, + data2: 0, + data3: 0, + data4: [0u8; 8], + }; - let guid = unsafe { CoCreateGuid().expect("Unable to CoCreateGuid") }; + unsafe { CoCreateGuid(&mut guid); } let uuid = Uuid::from_fields(guid.data1, guid.data2, guid.data3, &guid.data4); From 988347735343e785b8de488387cbb2bb3a1e464e Mon Sep 17 00:00:00 2001 From: sn99 Date: Mon, 12 Sep 2022 20:09:28 +0530 Subject: [PATCH 3/3] Migrate from winapi to windows-sys --- Cargo.toml | 6 +-- examples/windows_guid.rs | 86 +++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8747f611..303ad3dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -164,9 +164,9 @@ version = "1.0.52" [dev-dependencies.rustversion] version = "1" -[target.'cfg(windows)'.dev-dependencies.winapi] -version = "0.3" -features = ["combaseapi", "impl-default"] +[target.'cfg(windows)'.dev-dependencies.windows-sys] +version = "0.36.1" +features = ["Win32_System_Com"] [workspace] members = [ diff --git a/examples/windows_guid.rs b/examples/windows_guid.rs index 33404b1b..320f7a3b 100644 --- a/examples/windows_guid.rs +++ b/examples/windows_guid.rs @@ -11,35 +11,35 @@ #[cfg(windows)] fn guid_to_uuid() { use uuid::Uuid; - use winapi::shared::guiddef; + use windows_sys::core; - let guid_in = guiddef::GUID { - Data1: 0x4a35229d, - Data2: 0x5527, - Data3: 0x4f30, - Data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], + let guid_in = core::GUID { + data1: 0x4a35229d, + data2: 0x5527, + data3: 0x4f30, + data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], }; - let uuid = Uuid::from_fields(guid_in.Data1, guid_in.Data2, guid_in.Data3, &guid_in.Data4); + let uuid = Uuid::from_fields(guid_in.data1, guid_in.data2, guid_in.data3, &guid_in.data4); let guid_out = { let fields = uuid.as_fields(); - guiddef::GUID { - Data1: fields.0, - Data2: fields.1, - Data3: fields.2, - Data4: *fields.3, + core::GUID { + data1: fields.0, + data2: fields.1, + data3: fields.2, + data4: *fields.3, } }; assert_eq!( - (guid_in.Data1, guid_in.Data2, guid_in.Data3, guid_in.Data4), + (guid_in.data1, guid_in.data2, guid_in.data3, guid_in.data4), ( - guid_out.Data1, - guid_out.Data2, - guid_out.Data3, - guid_out.Data4 + guid_out.data1, + guid_out.data2, + guid_out.data3, + guid_out.data4 ) ); } @@ -48,39 +48,39 @@ fn guid_to_uuid() { #[cfg(windows)] fn guid_to_uuid_le_encoded() { use uuid::Uuid; - use winapi::shared::guiddef; + use windows_sys::core; // A GUID might not be encoded directly as a UUID // If its fields are stored in little-endian order they might // need to be flipped. Whether or not this is necessary depends // on the source of the GUID - let guid_in = guiddef::GUID { - Data1: 0x9d22354a, - Data2: 0x2755, - Data3: 0x304f, - Data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], + let guid_in = core::GUID { + data1: 0x9d22354a, + data2: 0x2755, + data3: 0x304f, + data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], }; - let uuid = Uuid::from_fields_le(guid_in.Data1, guid_in.Data2, guid_in.Data3, &guid_in.Data4); + let uuid = Uuid::from_fields_le(guid_in.data1, guid_in.data2, guid_in.data3, &guid_in.data4); let guid_out = { let fields = uuid.to_fields_le(); - guiddef::GUID { - Data1: fields.0, - Data2: fields.1, - Data3: fields.2, - Data4: *fields.3, + core::GUID { + data1: fields.0, + data2: fields.1, + data3: fields.2, + data4: *fields.3, } }; assert_eq!( - (guid_in.Data1, guid_in.Data2, guid_in.Data3, guid_in.Data4), + (guid_in.data1, guid_in.data2, guid_in.data3, guid_in.data4), ( - guid_out.Data1, - guid_out.Data2, - guid_out.Data3, - guid_out.Data4 + guid_out.data1, + guid_out.data2, + guid_out.data3, + guid_out.data4 ) ); } @@ -89,15 +89,19 @@ fn guid_to_uuid_le_encoded() { #[cfg(windows)] fn uuid_from_cocreateguid() { use uuid::{Uuid, Variant, Version}; - use winapi::{shared::guiddef, um::combaseapi::CoCreateGuid}; - - let mut guid = guiddef::GUID::default(); + use windows_sys::core; + use windows_sys::Win32::System::Com::CoCreateGuid; + + let mut guid = core::GUID { + data1: 0, + data2: 0, + data3: 0, + data4: [0u8; 8], + }; - unsafe { - CoCreateGuid(&mut guid as *mut _); - } + unsafe { CoCreateGuid(&mut guid); } - let uuid = Uuid::from_fields(guid.Data1, guid.Data2, guid.Data3, &guid.Data4); + let uuid = Uuid::from_fields(guid.data1, guid.data2, guid.data3, &guid.data4); assert_eq!(Variant::RFC4122, uuid.get_variant()); assert_eq!(Some(Version::Random), uuid.get_version());