diff --git a/Cargo.toml b/Cargo.toml index 57253c8..b1f4892 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,13 +13,11 @@ license = "MIT OR Apache-2.0" exclude = ["Generator/**"] [dependencies] -winapi = "0.2.8" -runtimeobject-sys = "0.2.0" -ole32-sys = "0.2.0" -oleaut32-sys = "0.2.0" +winapi = { version = "0.3", features = ["winnt", "combaseapi", "oleauto", "roapi", "roerrorapi", "hstring", "winstring", "winerror", "restrictederrorinfo"] } [features] nightly = [] +lang-compat = [] windows-applicationmodel = [] windows-data = [] windows-devices = [] diff --git a/README.md b/README.md index 3c7729c..72fcedf 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Since we can not yet guarantee the safety of the generated wrappers, all methods Creating custom WinRT classes using inheritance is not yet supported, so it is currently not possible to create user interfaces using *XAML*. ## Prerequisites -Using this crate requires at least Rust 1.13 and the MSVC toolchain (because there is a bug in one of MinGW's import libraries). -Additional nightly features (e.g. generating enum variants as associated constants) can be enabled with the `nightly` Cargo feature. +Using this crate requires at least Rust 1.20. A compatibility mode that requires only Rust 1.15 can be enabled with the `lang-compat` Cargo feature. +Additional nightly features (e.g. using specialization) can be enabled with the `nightly` Cargo feature. ## Design All definitions are automatically generated from *WinMD* metadata files. diff --git a/examples/test.rs b/examples/test.rs index 4b7a3a0..4d77615 100644 --- a/examples/test.rs +++ b/examples/test.rs @@ -1,7 +1,5 @@ extern crate winapi as w; extern crate winrt; -// TODO: don't use functions from runtimeobject directly -extern crate runtimeobject; use std::ptr; @@ -36,8 +34,8 @@ fn run() { println!("{}", device_selector); unsafe { - use runtimeobject::*; - use ::w::S_OK; + use w::shared::winerror::S_OK; + use w::winrt::roerrorapi::GetRestrictedErrorInfo; // Test some error reporting by using an invalid device selector let wrong_deviceselector: FastHString = "Foobar".into(); @@ -122,7 +120,7 @@ fn run() { let array = &mut [true, false, false, true]; let boxed_array = PropertyValue::create_boolean_array(array); let boxed_array = boxed_array.unwrap().query_interface::().unwrap(); - assert_eq!(unsafe { boxed_array.get_type().unwrap() }, PropertyType_BooleanArray); + assert_eq!(unsafe { boxed_array.get_type().unwrap() }, PropertyType::BooleanArray); let boxed_array = boxed_array.query_interface::>().unwrap(); let returned_array = unsafe { boxed_array.get_value().unwrap() }; println!("{:?} = {:?}", array, &returned_array[..]); @@ -133,7 +131,7 @@ fn run() { let array = &mut [&*str1, &*str2, &*str1, &*str2]; let boxed_array = PropertyValue::create_string_array(array); let boxed_array = boxed_array.unwrap().query_interface::().unwrap(); - assert_eq!(unsafe { boxed_array.get_type().unwrap() }, PropertyType_StringArray); + assert_eq!(unsafe { boxed_array.get_type().unwrap() }, PropertyType::StringArray); let boxed_array = boxed_array.query_interface::>().unwrap(); let returned_array = unsafe { boxed_array.get_value().unwrap() }; assert_eq!(array.len(), returned_array.len()); diff --git a/examples/toast_notify.rs b/examples/toast_notify.rs index ee460e6..f42a492 100644 --- a/examples/toast_notify.rs +++ b/examples/toast_notify.rs @@ -17,7 +17,7 @@ fn main() { fn run() { unsafe { // Get a toast XML template - let toast_xml = ToastNotificationManager::get_template_content(ToastTemplateType_ToastText02).unwrap(); + let toast_xml = ToastNotificationManager::get_template_content(ToastTemplateType::ToastText02).unwrap(); // Fill in the text elements let toast_text_elements = toast_xml.get_elements_by_tag_name(&FastHString::new("text")).unwrap(); diff --git a/src/bstr.rs b/src/bstr.rs index bf8c952..3119901 100644 --- a/src/bstr.rs +++ b/src/bstr.rs @@ -1,8 +1,10 @@ use ::std::ptr; use ::std::fmt; -use ::w::*; -use ::oleaut32::*; +use w::shared::wtypes::BSTR; +use w::shared::basetsd::UINT32; +use w::shared::wtypesbase::OLECHAR; +use w::um::oleauto::{SysStringLen, SysAllocStringLen, SysFreeString}; // TODO: move to separate crate? diff --git a/src/cominterfaces.rs b/src/cominterfaces.rs index 316eb98..0548763 100644 --- a/src/cominterfaces.rs +++ b/src/cominterfaces.rs @@ -1,4 +1,5 @@ -use ::Guid; +use Guid; +use w::um::unknwnbase::IUnknownVtbl; /// Marker trait for all COM-compatible interfaces. pub trait ComInterface { @@ -20,15 +21,15 @@ pub trait ComIid { DEFINE_IID!(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); /// Re-export from WinAPI crate -pub type IUnknown = ::w::IUnknown; +pub type IUnknown = ::w::um::unknwnbase::IUnknown; impl ComIid for IUnknown { #[inline] fn iid() -> &'static Guid { &IID_IUnknown } } -impl ComInterface for IUnknown { type Vtbl = ::w::IUnknownVtbl; } +impl ComInterface for IUnknown { type Vtbl = IUnknownVtbl; } DEFINE_IID!(IID_IRestrictedErrorInfo, 0x82BA7092, 0x4C88, 0x427D, 0xA7, 0xBC, 0x16, 0xDD, 0x93, 0xFE, 0xB6, 0x7E); /// Re-export from WinAPI crate -pub type IRestrictedErrorInfo = ::w::IRestrictedErrorInfo; -pub type IRestrictedErrorInfoVtbl = ::w::IRestrictedErrorInfoVtbl; +pub type IRestrictedErrorInfo = ::w::um::restrictederrorinfo::IRestrictedErrorInfo; +pub type IRestrictedErrorInfoVtbl = ::w::um::restrictederrorinfo::IRestrictedErrorInfoVtbl; impl ComIid for IRestrictedErrorInfo { #[inline] fn iid() -> &'static Guid { &IID_IRestrictedErrorInfo } } impl ComInterface for IRestrictedErrorInfo { type Vtbl = IRestrictedErrorInfoVtbl; } @@ -38,7 +39,7 @@ DEFINE_IID!(IID_IAgileObject, 0x94EA2B94, 0xE9CC, 0x49E0, 0xC0, 0xFF, 0xEE, 0x64 /// It inherits from `IUnknown` and does not have additional members. #[repr(C)] #[derive(Debug)] pub struct IAgileObject { - lpVtbl: *const ::w::IUnknownVtbl // IAgileObject has no methods besides what IUnknown has + lpVtbl: *const IUnknownVtbl // IAgileObject has no methods besides what IUnknown has } impl ::std::ops::Deref for IAgileObject { type Target = IUnknown; @@ -54,4 +55,4 @@ impl ::std::ops::DerefMut for IAgileObject { } } impl ComIid for IAgileObject { #[inline] fn iid() -> &'static Guid { &IID_IAgileObject } } -impl ComInterface for IAgileObject { type Vtbl = ::w::IUnknownVtbl; } \ No newline at end of file +impl ComInterface for IAgileObject { type Vtbl = IUnknownVtbl; } \ No newline at end of file diff --git a/src/comptr.rs b/src/comptr.rs index 18cfcd8..f884a39 100644 --- a/src/comptr.rs +++ b/src/comptr.rs @@ -3,6 +3,12 @@ use std::fmt; use std::ptr; use ::{ComIid, ComInterface, RtInterface, RtClassInterface, IInspectable, Guid}; +use w::shared::ntdef::VOID; +use w::shared::minwindef::LPVOID; +use w::shared::winerror::S_OK; +use w::um::unknwnbase::IUnknown; +use w::um::combaseapi::CoTaskMemFree; + /// Smart pointer for Windows Runtime objects. This pointer automatically maintains the /// reference count of the underlying COM object. #[repr(C)] #[derive(Debug)] @@ -19,11 +25,11 @@ impl fmt::Pointer for ComPtr { #[inline] pub fn query_interface(interface: &T) -> Option> where Target: ComIid, T: ComInterface { let iid: &'static Guid = Target::iid(); - let as_unknown = unsafe { &mut *(interface as *const T as *mut T as *mut ::w::IUnknown) }; + let as_unknown = unsafe { &mut *(interface as *const T as *mut T as *mut IUnknown) }; let mut res = ptr::null_mut(); unsafe { - match as_unknown.QueryInterface(iid.as_ref(), &mut res as *mut _ as *mut *mut ::w::VOID) { - ::w::S_OK => Some(ComPtr::wrap(res)), + match as_unknown.QueryInterface(iid.as_ref(), &mut res as *mut _ as *mut *mut VOID) { + S_OK => Some(ComPtr::wrap(res)), _ => None } } @@ -53,8 +59,8 @@ impl ComPtr { /// Returns the underlying WinRT or COM object as a reference to an `IUnknown` object. #[inline] - fn as_unknown(&self) -> &mut ::w::IUnknown { - unsafe { &mut *(self.0 as *mut ::w::IUnknown) } + fn as_unknown(&self) -> &mut IUnknown { + unsafe { &mut *(self.0 as *mut IUnknown) } } /// Changes the type of the underlying COM object to a different interface without doing `QueryInterface`. @@ -173,7 +179,7 @@ impl Drop for ComArray where T: ::RtType { fn drop(&mut self) { unsafe { ::std::ptr::drop_in_place(&mut self[..]); - ::ole32::CoTaskMemFree(self.first as ::w::LPVOID) + CoTaskMemFree(self.first as LPVOID) }; } } diff --git a/src/guid.rs b/src/guid.rs index c7db95e..6d2a899 100644 --- a/src/guid.rs +++ b/src/guid.rs @@ -1,5 +1,7 @@ use std::{fmt, cmp, mem}; +use w::shared::guiddef::GUID; + /// Represents a GUID type in the Windows Runtime type system. #[derive(Copy, Clone)] #[repr(C)] @@ -10,16 +12,16 @@ pub struct Guid { // TODO: fields should not be public (requires const fn constr pub Data4: [u8; 8] } -impl AsRef<::w::GUID> for Guid { +impl AsRef for Guid { #[inline] - fn as_ref(&self) -> &::w::GUID { + fn as_ref(&self) -> &GUID { unsafe { mem::transmute(self) } } } -impl From<::w::GUID> for Guid { +impl From for Guid { #[inline] - fn from(guid: ::w::GUID) -> Self { + fn from(guid: GUID) -> Self { unsafe { mem::transmute(guid) } } } diff --git a/src/hstring.rs b/src/hstring.rs index 858972e..31b06f3 100644 --- a/src/hstring.rs +++ b/src/hstring.rs @@ -1,12 +1,17 @@ -use ::std::ptr; -use ::std::fmt; -use ::std::cmp; -use ::std::mem; -use ::std::marker::PhantomData; -use ::std::ops::Deref; - -use ::w::*; -use ::runtimeobject::*; +use std::ptr; +use std::fmt; +use std::cmp; +use std::mem; +use std::marker::PhantomData; +use std::ops::Deref; + +use w::shared::basetsd::UINT32; +use w::shared::ntdef::LPCWSTR; +use w::shared::winerror::S_OK; +use w::winrt::hstring::{HSTRING, HSTRING__, HSTRING_HEADER}; +use w::winrt::winstring::{WindowsCreateString, WindowsGetStringLen, WindowsIsStringEmpty, + WindowsGetStringRawBuffer, WindowsCreateStringReference, + WindowsDuplicateString, WindowsDeleteString, WindowsCompareStringOrdinal}; // For some information about HSTRINGs, see http://ksav.com.np/tech/2016/06/16/raymonds-complete-guide-to-hstring-semantics/ @@ -34,20 +39,9 @@ fn internal_cmp(left: HSTRING, right: HSTRING) -> cmp::Ordering { } #[inline] -#[cfg(target_arch = "x86_64")] -fn zero_header() -> HSTRING_HEADER { - HSTRING_HEADER { - Reserved: [ptr::null_mut(); 0], - Reserved2: [0; 24] - } -} - -#[inline] -#[cfg(target_arch = "x86")] fn zero_header() -> HSTRING_HEADER { HSTRING_HEADER { - Reserved: [ptr::null_mut(); 0], - Reserved2: [0; 20] + Reserved: unsafe { mem::zeroed() } } } @@ -569,8 +563,8 @@ mod tests { #[test] fn check_sizes() { use ::std::mem::size_of; - assert_eq!(size_of::<::HString>(), size_of::<::w::HSTRING>()); - assert_eq!(size_of::<&::HStringArg>(), size_of::<::w::HSTRING>()); + assert_eq!(size_of::<::HString>(), size_of::<::w::winrt::hstring::HSTRING>()); + assert_eq!(size_of::<&::HStringArg>(), size_of::<::w::winrt::hstring::HSTRING>()); } #[test] diff --git a/src/lib.rs b/src/lib.rs index 4865860..56273be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,20 +25,16 @@ #![cfg_attr(test,feature(test))] #![cfg_attr(feature = "nightly", feature(specialization))] -#![cfg_attr(feature = "nightly", feature(associated_consts))] #![allow(dead_code,non_upper_case_globals,non_snake_case)] extern crate winapi as w; -extern crate runtimeobject; -extern crate ole32; -extern crate oleaut32; mod guid; pub use guid::Guid; ///Represents the trust level of an activatable class (re-export from WinAPI crate) -pub type TrustLevel = ::w::TrustLevel; +pub type TrustLevel = ::w::winrt::inspectable::TrustLevel; // Compared to the DEFINE_GUID macro from winapi, this one creates a private const macro_rules! DEFINE_IID { @@ -85,7 +81,9 @@ mod prelude { pub use ::comptr::{ComPtr, ComArray}; pub use ::hstring::{HString, HStringArg}; pub use ::result::{Result, HRESULT}; - pub use ::w::{IUnknownVtbl, S_OK, HSTRING}; + pub use ::w::winrt::hstring::HSTRING; + pub use ::w::shared::winerror::S_OK; + pub use ::w::um::unknwnbase::IUnknownVtbl; pub use ::std::ptr::null_mut; pub use ::std::mem::zeroed; pub use ::guid::Guid; @@ -94,4 +92,15 @@ mod prelude { pub fn err(hr: ::result::HRESULT) -> ::result::Result { Err(::result::Error::from_hresult(hr)) } -} \ No newline at end of file +} + +// For definitions that are different depending on the lang-compat feature +#[cfg(not(feature = "lang-compat"))] +mod langcompat { + pub const ASYNC_STATUS_COMPLETED: ::windows::foundation::AsyncStatus = ::windows::foundation::AsyncStatus::Completed; +} + +#[cfg(feature = "lang-compat")] +mod langcompat { + pub const ASYNC_STATUS_COMPLETED: ::windows::foundation::AsyncStatus = ::windows::foundation::AsyncStatus_Completed; +} diff --git a/src/result.rs b/src/result.rs index b5e56ce..ccab289 100644 --- a/src/result.rs +++ b/src/result.rs @@ -1,5 +1,5 @@ /// Re-export from WinAPI crate -pub type HRESULT = ::w::HRESULT; +pub type HRESULT = ::w::um::winnt::HRESULT; // TODO: add more codes from https://msdn.microsoft.com/en-us/library/windows/desktop/dd542643(v=vs.85).aspx, especially the `RO_`-prefixed @@ -25,20 +25,21 @@ impl Error { #[inline] pub fn from_hresult(hr: HRESULT) -> Error { use Error::*; + use ::w::shared::winerror::*; match hr { - ::w::E_ABORT => OperationAborted, - ::w::E_ACCESSDENIED => AccessDenied, - ::w::E_FAIL => UnspecifiedFailure, - ::w::E_HANDLE => InvalidHandle, - ::w::E_INVALIDARG => InvalidArgument, - ::w::E_NOINTERFACE => NoSuchInterface, - ::w::E_NOTIMPL => NotImplemented, - ::w::E_OUTOFMEMORY => OutOfMemory, - ::w::E_POINTER => InvalidPointer, - ::w::E_UNEXPECTED => UnexpectedFailure, - ::w::E_BOUNDS => OutOfBounds, - ::w::E_ILLEGAL_METHOD_CALL => IllegalMethodCall, + E_ABORT => OperationAborted, + E_ACCESSDENIED => AccessDenied, + E_FAIL => UnspecifiedFailure, + E_HANDLE => InvalidHandle, + E_INVALIDARG => InvalidArgument, + E_NOINTERFACE => NoSuchInterface, + E_NOTIMPL => NotImplemented, + E_OUTOFMEMORY => OutOfMemory, + E_POINTER => InvalidPointer, + E_UNEXPECTED => UnexpectedFailure, + E_BOUNDS => OutOfBounds, + E_ILLEGAL_METHOD_CALL => IllegalMethodCall, _ => Other(hr) } } @@ -46,20 +47,21 @@ impl Error { #[inline] pub fn as_hresult(&self) -> HRESULT { use Error::*; + use ::w::shared::winerror::*; match *self { - OperationAborted => ::w::E_ABORT, - AccessDenied => ::w::E_ACCESSDENIED, - UnspecifiedFailure => ::w::E_FAIL, - InvalidHandle => ::w::E_HANDLE, - InvalidArgument => ::w::E_INVALIDARG, - NoSuchInterface => ::w::E_NOINTERFACE, - NotImplemented => ::w::E_NOTIMPL, - OutOfMemory => ::w::E_OUTOFMEMORY, - InvalidPointer => ::w::E_POINTER, - UnexpectedFailure => ::w::E_UNEXPECTED, - OutOfBounds => ::w::E_BOUNDS, - IllegalMethodCall => ::w::E_ILLEGAL_METHOD_CALL, + OperationAborted => E_ABORT, + AccessDenied => E_ACCESSDENIED, + UnspecifiedFailure => E_FAIL, + InvalidHandle => E_HANDLE, + InvalidArgument => E_INVALIDARG, + NoSuchInterface => E_NOINTERFACE, + NotImplemented => E_NOTIMPL, + OutOfMemory => E_OUTOFMEMORY, + InvalidPointer => E_POINTER, + UnexpectedFailure => E_UNEXPECTED, + OutOfBounds => E_BOUNDS, + IllegalMethodCall => E_ILLEGAL_METHOD_CALL, Other(hr) => hr, } } diff --git a/src/rt/async.rs b/src/rt/async.rs index b2b4039..8d7aa93 100644 --- a/src/rt/async.rs +++ b/src/rt/async.rs @@ -40,7 +40,8 @@ macro_rules! impl_blocking_wait { fn blocking_wait(&self) { let info = ::comptr::query_interface::<_, IAsyncInfo>(self).unwrap(); let status = unsafe { info.get_status().unwrap() }; - if status == ::windows::foundation::AsyncStatus_Completed { + + if status == ::langcompat::ASYNC_STATUS_COMPLETED { return; } diff --git a/src/rt/handler.rs b/src/rt/handler.rs index a7d7438..fdee061 100644 --- a/src/rt/handler.rs +++ b/src/rt/handler.rs @@ -1,15 +1,14 @@ use std::sync::atomic; -use ::{ - IUnknown, - IAgileObject, - ComInterface, - ComIid, - ComPtr, - Guid -}; +use {IUnknown, IAgileObject, ComInterface, ComIid, ComPtr, Guid}; -use ::w::{S_OK, HRESULT, VOID, REFIID, ULONG, IUnknownVtbl}; +use w::shared::ntdef::{VOID, ULONG}; +use w::shared::winerror::S_OK; +use w::shared::winerror::E_NOINTERFACE; +use w::shared::guiddef::REFIID; +use w::um::unknwnbase::IUnknownVtbl; + +use result::HRESULT; #[repr(C)] pub struct ComRepr { @@ -56,7 +55,7 @@ pub unsafe extern "system" fn ComReprHandler_QueryInterface(this_: *mut IU // IAgileObject is only supported for Send objects if guid != *IUnknown::iid() && guid != *IAgileObject::iid() && guid != *::iid() { *ppv = ::std::ptr::null_mut(); - return ::w::E_NOINTERFACE; + return E_NOINTERFACE; } *ppv = this_ as *mut _ as *mut VOID; ComRepr_AddRef::(this_ as *mut IUnknown); diff --git a/src/rt/mod.rs b/src/rt/mod.rs index 90ba21b..fee6f81 100644 --- a/src/rt/mod.rs +++ b/src/rt/mod.rs @@ -1,8 +1,14 @@ use std::ptr; use super::{ComInterface, HString, HStringReference, HStringArg, ComPtr, ComArray, ComIid, Guid}; +use HRESULT; -use w::{HRESULT, HSTRING, S_OK, S_FALSE, ULONG, TrustLevel, IID, CO_E_NOTINITIALIZED}; +use w::shared::ntdef::{VOID, ULONG}; +use w::shared::winerror::{S_OK, S_FALSE, CO_E_NOTINITIALIZED}; +use w::shared::guiddef::IID; +use w::um::unknwnbase::IUnknownVtbl; +use w::winrt::hstring::HSTRING; +use w::winrt::roapi::{RO_INIT_MULTITHREADED, RoInitialize, RoUninitialize, RoGetActivationFactory}; use self::gen::windows::foundation::collections::{ IIterable, @@ -12,7 +18,7 @@ use self::gen::windows::foundation::collections::{ /// Represents a single UTF-16 character. This is the standard character type in WinRT. #[derive(Clone, Copy)] #[repr(C)] -pub struct Char(pub ::w::wchar_t); // TODO: deref to u16 +pub struct Char(pub ::w::ctypes::wchar_t); // TODO: deref to u16 /// Marker trait for all Windows Runtime interfaces. They must inherit from `IInspectable`. pub unsafe trait RtInterface: ComInterface {} @@ -53,7 +59,7 @@ pub trait RtType { impl<'a> RtType for HString { type In = HStringArg; - type Abi = ::w::HSTRING; + type Abi = HSTRING; type Out = HString; #[doc(hidden)] #[inline] @@ -103,7 +109,7 @@ pub trait RtActivatable : RtNamedClass { fn get_activation_factory() -> ComPtr where Interface: RtInterface + ComIid { let mut res = ptr::null_mut(); let class_id = unsafe { HStringReference::from_utf16_unchecked(Self::name()) }; - let hr = unsafe { ::runtimeobject::RoGetActivationFactory(class_id.get(), ::iid().as_ref(), &mut res as *mut *mut _ as *mut *mut ::w::VOID) }; + let hr = unsafe { RoGetActivationFactory(class_id.get(), ::iid().as_ref(), &mut res as *mut *mut _ as *mut *mut VOID) }; if hr == S_OK { unsafe { ComPtr::wrap(res) } } else if hr == CO_E_NOTINITIALIZED { @@ -383,7 +389,7 @@ macro_rules! RT_DELEGATE { (delegate $interface:ident ($vtbl:ident, $imp:ident) [$iid:ident] { $(#[cfg($cond_attr:meta)])* fn Invoke(&self $(,$p:ident : $t:ty)*) -> HRESULT }) => { - RT_INTERFACE!{basic $interface($vtbl) : IUnknown(::w::IUnknownVtbl) [$iid] { + RT_INTERFACE!{basic $interface($vtbl) : IUnknown(IUnknownVtbl) [$iid] { $(#[cfg($cond_attr)])* fn Invoke(&self $(,$p : $t)*) -> HRESULT }} @@ -419,7 +425,7 @@ macro_rules! RT_DELEGATE { #[inline] fn get_vtbl() -> $vtbl { $vtbl { - parent: ::w::IUnknownVtbl { + parent: IUnknownVtbl { QueryInterface: ::rt::handler::ComReprHandler_QueryInterface::<$imp<_F_>, _>, AddRef: ::rt::handler::ComRepr_AddRef::<$imp<_F_>>, Release: ::rt::handler::ComRepr_Release::<$imp<_F_>>, @@ -453,7 +459,7 @@ macro_rules! RT_DELEGATE { (delegate $interface:ident<$($ht:ident),+> ($vtbl:ident, $imp:ident) [$iid:ident] { $(#[cfg($cond_attr:meta)])* fn Invoke(&self $(,$p:ident : $t:ty)*) -> HRESULT }) => { - RT_INTERFACE!{basic $interface<$($ht),+>($vtbl) : IUnknown(::w::IUnknownVtbl) [$iid] { + RT_INTERFACE!{basic $interface<$($ht),+>($vtbl) : IUnknown(IUnknownVtbl) [$iid] { $(#[cfg($cond_attr)])* fn Invoke(&self $(,$p : $t)*) -> HRESULT }} @@ -487,7 +493,7 @@ macro_rules! RT_DELEGATE { #[inline] fn get_vtbl() -> $vtbl<$($ht),+> { $vtbl::<$($ht),+> { - parent: ::w::IUnknownVtbl { + parent: IUnknownVtbl { QueryInterface: ::rt::handler::ComReprHandler_QueryInterface::<$imp<$($ht),+ , _F_>, _>, AddRef: ::rt::handler::ComRepr_AddRef::<$imp<$($ht),+ , _F_>>, Release: ::rt::handler::ComRepr_Release::<$imp<$($ht),+ , _F_>>, @@ -574,14 +580,9 @@ macro_rules! RT_ENUM { #[repr(C)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] #[allow(non_upper_case_globals)] pub struct $name(pub $t); - $(pub const $longvariant: $name = $name($value);)+ - - // TODO: - // Associated constants will be stable in 1.20 (see https://github.com/rust-lang/rust/issues/29646). - // We should remove the "nightly" flag here and instead introduce a "compat" flag (name TBD) - // that can be enabled to build on older versions of Rust. That flag would disable the associated constants - // and enable the old "longvariant" constants (which should be disabled by default). - #[cfg(feature = "nightly")] + $(#[cfg(feature = "lang-compat")] pub const $longvariant: $name = $name($value);)+ + + #[cfg(not(feature = "lang-compat"))] impl $name { $(pub const $variant: $name = $name($value);)+ } @@ -619,10 +620,10 @@ pub mod gen; // import auto-generated definitions (has to come after macro defin DEFINE_IID!(IID_IInspectable, 0xAF86E2E0, 0xB12D, 0x4c6a, 0x9C, 0x5A, 0xD7, 0xAA, 0x65, 0x10, 0x1E, 0x90); RT_INTERFACE!{ /// The `IInspectable` interface is the base interface for all Windows Runtime classes. -interface IInspectable(IInspectableVtbl): IUnknown(::w::IUnknownVtbl) [IID_IInspectable] { +interface IInspectable(IInspectableVtbl): IUnknown(IUnknownVtbl) [IID_IInspectable] { fn GetIids(&self, iidCount: *mut ULONG, iids: *mut *mut IID) -> HRESULT, fn GetRuntimeClassName(&self, className: *mut HSTRING) -> HRESULT, - fn GetTrustLevel(&self, trustLevel: *mut TrustLevel) -> HRESULT + fn GetTrustLevel(&self, trustLevel: *mut ::TrustLevel) -> HRESULT }} impl IInspectable { /// Returns the interfaces that are implemented by the current Windows Runtime object. @@ -631,17 +632,17 @@ impl IInspectable { let mut result = ::std::ptr::null_mut(); let mut count = 0; let hr = unsafe { ((*self.lpVtbl).GetIids)(self as *const _ as *mut _, &mut count, &mut result) }; - assert_eq!(hr, ::w::S_OK); + assert_eq!(hr, S_OK); let result = result as *mut Guid; // convert from ::w::GUID to (binary compatible) Guid unsafe { ComArray::from_raw(count, result) } } /// Returns the trust level of the current Windows Runtime object. #[inline] - pub fn get_trust_level(&self) -> TrustLevel { + pub fn get_trust_level(&self) -> ::TrustLevel { let mut result = unsafe { ::std::mem::zeroed() }; let hr = unsafe { ((*self.lpVtbl).GetTrustLevel)(self as *const _ as *mut _, &mut result) }; - assert_eq!(hr, ::w::S_OK); + assert_eq!(hr, S_OK); result } } @@ -651,7 +652,7 @@ impl ::comptr::HiddenGetRuntimeClassName for IInspectable { fn get_runtime_class_name(&self) -> HString { let mut result = ::std::ptr::null_mut(); let hr = unsafe { ((*self.lpVtbl).GetRuntimeClassName)(self as *const _ as *mut _, &mut result) }; - assert_eq!(hr, ::w::S_OK); + assert_eq!(hr, S_OK); unsafe { HString::wrap(result) } } } @@ -667,7 +668,7 @@ impl IActivationFactory { pub fn activate_instance(&self) -> ComPtr { let mut result = ::std::ptr::null_mut(); let hr = unsafe { ((*self.lpVtbl).ActivateInstance)(self as *const _ as *mut _, &mut result) }; - assert_eq!(hr, ::w::S_OK); + assert_eq!(hr, S_OK); unsafe { ComPtr::wrap(result) } } } @@ -684,7 +685,7 @@ impl RuntimeContext { /// as long as any Windows Runtime object is still alive. #[inline] pub fn init() -> RuntimeContext { - let hr = unsafe { ::runtimeobject::RoInitialize(::w::RO_INIT_MULTITHREADED) }; + let hr = unsafe { RoInitialize(RO_INIT_MULTITHREADED) }; assert!(hr == S_OK || hr == S_FALSE, "failed to call RoInitialize: error {}", hr); /*let mut f: ::w::UINT32 = 0; assert!(RoGetErrorReportingFlags(&mut f) == S_OK); @@ -703,6 +704,6 @@ impl RuntimeContext { impl Drop for RuntimeContext { #[inline] fn drop(&mut self) { - unsafe { ::runtimeobject::RoUninitialize() }; + unsafe { RoUninitialize() }; } } \ No newline at end of file