Skip to content

Instantly share code, notes, and snippets.

@kennykerr
Created July 24, 2020 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kennykerr/cfc458797b4326af2acc74784edb396e to your computer and use it in GitHub Desktop.
Save kennykerr/cfc458797b4326af2acc74784edb396e to your computer and use it in GitHub Desktop.
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