Created
July 24, 2020 15:19
-
-
Save kennykerr/cfc458797b4326af2acc74784edb396e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
com::declare!( | |
// A COM interface declared here | |
[uuid(...)] | |
interface IOldSchool {...} | |
// A COM class declared here (not defined here) | |
[uuid(...)] | |
class ExternalClass : IOldSchool; | |
// A COM class defined here | |
[uuid(...)] | |
class ExportedClass : IOldSchool {...} | |
// A local COM class defined here (no uuid and not exported) | |
class LocalClass : IOldSchool {...} | |
); | |
impl ExportedClass { | |
fn new() -> Result<ExportedClass> { | |
Self {...} | |
} | |
} | |
impl LocalClass { | |
fn new() -> Result<ExportedClass> { | |
Self {...} | |
} | |
} | |
winrt::declare!( | |
// A WinRT struct defined here | |
struct StructType { x: i32, y: i32 }; | |
// A WinRT interface defined here (uuid is inferred) | |
interface IInterfaceType { | |
fn method(&self) -> Result<i32>; | |
} | |
// A WinRT class defined here (implements both WinRT and COM interfaces) | |
class ClassyType : windows::foundation::IStringable, IInterfaceType, IOldSchool { | |
value : String | |
// constructors and statics declared here so we can wire up class factory | |
fn new() -> Result<ClassyType>; | |
fn something_static() -> Result<i32>; | |
} | |
); | |
impl ClassyType { | |
fn new() -> Result<ClassyType> { | |
Ok(Self { value: "value".to_owned() }) | |
} | |
fn something_static() -> Result<i32> { | |
Ok(123) | |
} | |
} | |
impl windows::foundation::IStringable for ClassyType { | |
fn to_string(&self) -> Result<winrt::HString> { | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment