Skip to content

Commit

Permalink
samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Nov 30, 2024
1 parent 65671a0 commit 8b10d63
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 139 deletions.
10 changes: 4 additions & 6 deletions crates/samples/components/json_validator_winrt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ fn main() {
panic!("Failed to run midlrt");
}

if let Err(error) = windows_bindgen::bindgen([
windows_bindgen::bindgen([
"--in",
"sample.winmd",
&metadata_dir,
"--out",
"src/bindings.rs",
"--filter",
"Sample",
"--config",
"implement",
]) {
panic!("{error}");
}
"--flat",
"--implement",
]);
}
170 changes: 85 additions & 85 deletions crates/samples/components/json_validator_winrt/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,63 @@
dead_code,
clippy::all
)]

#[repr(transparent)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct JsonValidator(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(
JsonValidator,
windows_core::IUnknown,
windows_core::IInspectable
);
impl JsonValidator {
pub fn Validate(
&self,
value: &windows_core::HSTRING,
) -> windows_core::Result<windows_core::HSTRING> {
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).Validate)(
windows_core::Interface::as_raw(this),
core::mem::transmute_copy(value),
&mut result__,
)
.map(|| core::mem::transmute(result__))
}
}
pub fn CreateInstance(schema: &windows_core::HSTRING) -> windows_core::Result<JsonValidator> {
Self::IJsonValidatorFactory(|this| unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).CreateInstance)(
windows_core::Interface::as_raw(this),
core::mem::transmute_copy(schema),
&mut result__,
)
.and_then(|| windows_core::Type::from_abi(result__))
})
}
fn IJsonValidatorFactory<R, F: FnOnce(&IJsonValidatorFactory) -> windows_core::Result<R>>(
callback: F,
) -> windows_core::Result<R> {
static SHARED: windows_core::imp::FactoryCache<JsonValidator, IJsonValidatorFactory> =
windows_core::imp::FactoryCache::new();
SHARED.call(callback)
}
}
impl windows_core::RuntimeType for JsonValidator {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_class::<Self, IJsonValidator>();
}
unsafe impl windows_core::Interface for JsonValidator {
type Vtable = <IJsonValidator as windows_core::Interface>::Vtable;
const IID: windows_core::GUID = <IJsonValidator as windows_core::Interface>::IID;
}
impl windows_core::RuntimeName for JsonValidator {
const NAME: &'static str = "Sample.JsonValidator";
}
unsafe impl Send for JsonValidator {}
unsafe impl Sync for JsonValidator {}
windows_core::imp::define_interface!(
IJsonValidator,
IJsonValidator_Vtbl,
Expand All @@ -16,30 +73,21 @@ impl windows_core::RuntimeType for IJsonValidator {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
#[repr(C)]
pub struct IJsonValidator_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub Validate: unsafe extern "system" fn(
*mut core::ffi::c_void,
core::mem::MaybeUninit<windows_core::HSTRING>,
*mut core::mem::MaybeUninit<windows_core::HSTRING>,
) -> windows_core::HRESULT,
impl windows_core::RuntimeName for IJsonValidator {
const NAME: &'static str = "Sample.IJsonValidator";
}
pub trait IJsonValidator_Impl: Sized + windows_core::IUnknownImpl {
pub trait IJsonValidator_Impl: windows_core::IUnknownImpl {
fn Validate(
&self,
value: &windows_core::HSTRING,
) -> windows_core::Result<windows_core::HSTRING>;
}
impl windows_core::RuntimeName for IJsonValidator {
const NAME: &'static str = "Sample.IJsonValidator";
}
impl IJsonValidator_Vtbl {
pub const fn new<Identity: IJsonValidator_Impl, const OFFSET: isize>() -> IJsonValidator_Vtbl {
pub const fn new<Identity: IJsonValidator_Impl, const OFFSET: isize>() -> Self {
unsafe extern "system" fn Validate<Identity: IJsonValidator_Impl, const OFFSET: isize>(
this: *mut core::ffi::c_void,
value: core::mem::MaybeUninit<windows_core::HSTRING>,
result__: *mut core::mem::MaybeUninit<windows_core::HSTRING>,
value: *mut core::ffi::c_void,
result__: *mut *mut core::ffi::c_void,
) -> windows_core::HRESULT {
let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
match IJsonValidator_Impl::Validate(this, core::mem::transmute(&value)) {
Expand All @@ -60,6 +108,15 @@ impl IJsonValidator_Vtbl {
iid == &<IJsonValidator as windows_core::Interface>::IID
}
}
#[repr(C)]
pub struct IJsonValidator_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub Validate: unsafe extern "system" fn(
*mut core::ffi::c_void,
*mut core::ffi::c_void,
*mut *mut core::ffi::c_void,
) -> windows_core::HRESULT,
}
windows_core::imp::define_interface!(
IJsonValidatorFactory,
IJsonValidatorFactory_Vtbl,
Expand All @@ -69,31 +126,21 @@ impl windows_core::RuntimeType for IJsonValidatorFactory {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
#[repr(C)]
pub struct IJsonValidatorFactory_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub CreateInstance: unsafe extern "system" fn(
*mut core::ffi::c_void,
core::mem::MaybeUninit<windows_core::HSTRING>,
*mut *mut core::ffi::c_void,
) -> windows_core::HRESULT,
impl windows_core::RuntimeName for IJsonValidatorFactory {
const NAME: &'static str = "Sample.IJsonValidatorFactory";
}
pub trait IJsonValidatorFactory_Impl: Sized + windows_core::IUnknownImpl {
pub trait IJsonValidatorFactory_Impl: windows_core::IUnknownImpl {
fn CreateInstance(&self, schema: &windows_core::HSTRING)
-> windows_core::Result<JsonValidator>;
}
impl windows_core::RuntimeName for IJsonValidatorFactory {
const NAME: &'static str = "Sample.IJsonValidatorFactory";
}
impl IJsonValidatorFactory_Vtbl {
pub const fn new<Identity: IJsonValidatorFactory_Impl, const OFFSET: isize>(
) -> IJsonValidatorFactory_Vtbl {
pub const fn new<Identity: IJsonValidatorFactory_Impl, const OFFSET: isize>() -> Self {
unsafe extern "system" fn CreateInstance<
Identity: IJsonValidatorFactory_Impl,
const OFFSET: isize,
>(
this: *mut core::ffi::c_void,
schema: core::mem::MaybeUninit<windows_core::HSTRING>,
schema: *mut core::ffi::c_void,
result__: *mut *mut core::ffi::c_void,
) -> windows_core::HRESULT {
let this: &Identity = &*((this as *const *const ()).offset(OFFSET) as *const Identity);
Expand All @@ -116,59 +163,12 @@ impl IJsonValidatorFactory_Vtbl {
iid == &<IJsonValidatorFactory as windows_core::Interface>::IID
}
}
#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct JsonValidator(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(
JsonValidator,
windows_core::IUnknown,
windows_core::IInspectable
);
impl JsonValidator {
pub fn Validate(
&self,
value: &windows_core::HSTRING,
) -> windows_core::Result<windows_core::HSTRING> {
let this = self;
unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).Validate)(
windows_core::Interface::as_raw(this),
core::mem::transmute_copy(value),
&mut result__,
)
.and_then(|| windows_core::Type::from_abi(result__))
}
}
pub fn CreateInstance(schema: &windows_core::HSTRING) -> windows_core::Result<JsonValidator> {
Self::IJsonValidatorFactory(|this| unsafe {
let mut result__ = core::mem::zeroed();
(windows_core::Interface::vtable(this).CreateInstance)(
windows_core::Interface::as_raw(this),
core::mem::transmute_copy(schema),
&mut result__,
)
.and_then(|| windows_core::Type::from_abi(result__))
})
}
fn IJsonValidatorFactory<R, F: FnOnce(&IJsonValidatorFactory) -> windows_core::Result<R>>(
callback: F,
) -> windows_core::Result<R> {
static SHARED: windows_core::imp::FactoryCache<JsonValidator, IJsonValidatorFactory> =
windows_core::imp::FactoryCache::new();
SHARED.call(callback)
}
}
impl windows_core::RuntimeType for JsonValidator {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_class::<Self, IJsonValidator>();
}
unsafe impl windows_core::Interface for JsonValidator {
type Vtable = IJsonValidator_Vtbl;
const IID: windows_core::GUID = <IJsonValidator as windows_core::Interface>::IID;
}
impl windows_core::RuntimeName for JsonValidator {
const NAME: &'static str = "Sample.JsonValidator";
#[repr(C)]
pub struct IJsonValidatorFactory_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub CreateInstance: unsafe extern "system" fn(
*mut core::ffi::c_void,
*mut core::ffi::c_void,
*mut *mut core::ffi::c_void,
) -> windows_core::HRESULT,
}
unsafe impl Send for JsonValidator {}
unsafe impl Sync for JsonValidator {}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
fn main() {
if let Err(error) = windows_bindgen::bindgen([
windows_bindgen::bindgen([
"--in",
"../json_validator_winrt/sample.winmd",
&format!("{}\\System32\\WinMetadata", env!("windir")),
"--out",
"src/bindings.rs",
"--filter",
"Sample",
]) {
panic!("{error}");
}
"--flat",
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,9 @@
dead_code,
clippy::all
)]
windows_core::imp::define_interface!(
IJsonValidator,
IJsonValidator_Vtbl,
0xe09cb12b_b13c_5139_8c99_6140bf80deb9
);
impl windows_core::RuntimeType for IJsonValidator {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
#[repr(C)]
pub struct IJsonValidator_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub Validate: unsafe extern "system" fn(
*mut core::ffi::c_void,
core::mem::MaybeUninit<windows_core::HSTRING>,
*mut core::mem::MaybeUninit<windows_core::HSTRING>,
) -> windows_core::HRESULT,
}
windows_core::imp::define_interface!(
IJsonValidatorFactory,
IJsonValidatorFactory_Vtbl,
0x1cf4464e_ae9e_55d5_9539_0af4d8fc35aa
);
impl windows_core::RuntimeType for IJsonValidatorFactory {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
#[repr(C)]
pub struct IJsonValidatorFactory_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub CreateInstance: unsafe extern "system" fn(
*mut core::ffi::c_void,
core::mem::MaybeUninit<windows_core::HSTRING>,
*mut *mut core::ffi::c_void,
) -> windows_core::HRESULT,
}

#[repr(transparent)]
#[derive(PartialEq, Eq, Debug, Clone)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct JsonValidator(windows_core::IUnknown);
windows_core::imp::interface_hierarchy!(
JsonValidator,
Expand All @@ -64,7 +29,7 @@ impl JsonValidator {
core::mem::transmute_copy(value),
&mut result__,
)
.and_then(|| windows_core::Type::from_abi(result__))
.map(|| core::mem::transmute(result__))
}
}
pub fn CreateInstance(schema: &windows_core::HSTRING) -> windows_core::Result<JsonValidator> {
Expand All @@ -91,11 +56,47 @@ impl windows_core::RuntimeType for JsonValidator {
windows_core::imp::ConstBuffer::for_class::<Self, IJsonValidator>();
}
unsafe impl windows_core::Interface for JsonValidator {
type Vtable = IJsonValidator_Vtbl;
type Vtable = <IJsonValidator as windows_core::Interface>::Vtable;
const IID: windows_core::GUID = <IJsonValidator as windows_core::Interface>::IID;
}
impl windows_core::RuntimeName for JsonValidator {
const NAME: &'static str = "Sample.JsonValidator";
}
unsafe impl Send for JsonValidator {}
unsafe impl Sync for JsonValidator {}
windows_core::imp::define_interface!(
IJsonValidator,
IJsonValidator_Vtbl,
0xe09cb12b_b13c_5139_8c99_6140bf80deb9
);
impl windows_core::RuntimeType for IJsonValidator {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
#[repr(C)]
pub struct IJsonValidator_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub Validate: unsafe extern "system" fn(
*mut core::ffi::c_void,
*mut core::ffi::c_void,
*mut *mut core::ffi::c_void,
) -> windows_core::HRESULT,
}
windows_core::imp::define_interface!(
IJsonValidatorFactory,
IJsonValidatorFactory_Vtbl,
0x1cf4464e_ae9e_55d5_9539_0af4d8fc35aa
);
impl windows_core::RuntimeType for IJsonValidatorFactory {
const SIGNATURE: windows_core::imp::ConstBuffer =
windows_core::imp::ConstBuffer::for_interface::<Self>();
}
#[repr(C)]
pub struct IJsonValidatorFactory_Vtbl {
pub base__: windows_core::IInspectable_Vtbl,
pub CreateInstance: unsafe extern "system" fn(
*mut core::ffi::c_void,
*mut core::ffi::c_void,
*mut *mut core::ffi::c_void,
) -> windows_core::HRESULT,
}
4 changes: 2 additions & 2 deletions crates/samples/windows-sys/task_dialog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fn main() {
}
}

extern "system" fn callback(_: HWND, notification: i32, _: WPARAM, _: LPARAM, _: isize) -> HRESULT {
if notification == TDN_BUTTON_CLICKED {
extern "system" fn callback(_: HWND, notification: u32, _: WPARAM, _: LPARAM, _: isize) -> HRESULT {
if notification == TDN_BUTTON_CLICKED as _ {
println!("button clicked");
}

Expand Down
1 change: 0 additions & 1 deletion crates/samples/windows/core_app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct CoreApp();
#[allow(non_snake_case)]
impl IFrameworkViewSource_Impl for CoreApp_Impl {
fn CreateView(&self) -> Result<IFrameworkView> {
// TODO: need self query `self.into()` to support implementing both IFrameworkViewSource and IFrameworkView on the same object.
Ok(CoreAppView().into())
}
}
Expand Down
Loading

0 comments on commit 8b10d63

Please sign in to comment.