Debian Codegraph @

debian/rust-vendor/find-msvc-tools/src/winapi.rs

raw
1 // Copyright © 2015-2017 winapi-rs developers
2 // Licensed under the Apache License, Version 2.0
3 // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
4 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
5 // All files in the project carrying such notice may not be copied, modified, or distributed
6 // except according to those terms.
7
8 #![allow(bad_style, clippy::upper_case_acronyms)]
9
10 pub type wchar_t = u16;
11
12 pub use crate::windows_sys::{FILETIME, GUID, HRESULT, SAFEARRAY};
13
14 pub type REFIID = *const IID;
15 pub type IID = GUID;
16 pub type ULONG = core::ffi::c_ulong;
17 pub type DWORD = u32;
18 pub type LPFILETIME = *mut FILETIME;
19 pub type OLECHAR = WCHAR;
20 pub type WCHAR = wchar_t;
21 pub type LPCOLESTR = *const OLECHAR;
22 pub type LCID = DWORD;
23 pub type LPCWSTR = *const WCHAR;
24 pub type PULONGLONG = *mut ULONGLONG;
25 pub type ULONGLONG = u64;
26
27 pub trait Interface {
28 fn uuidof() -> GUID;
29 }
30
31 pub type LPSAFEARRAY = *mut SAFEARRAY;
32
33 macro_rules! DEFINE_GUID {
34 (
35 $name:ident, $l:expr, $w1:expr, $w2:expr,
36 $b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr
37 ) => {
38 pub const $name: $crate::winapi::GUID = $crate::winapi::GUID {
39 data1: $l,
40 data2: $w1,
41 data3: $w2,
42 data4: [$b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8],
43 };
44 };
45 }
46
47 macro_rules! RIDL {
48 (#[uuid($($uuid:expr),+)]
49 interface $interface:ident ($vtbl:ident) {$(
50 fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty,
51 )+}) => (
52 #[repr(C)]
53 pub struct $vtbl {
54 $(pub $method: unsafe extern "system" fn(
55 This: *mut $interface,
56 $($p: $t),*
57 ) -> $rtr,)+
58 }
59 #[repr(C)]
60 pub struct $interface {
61 pub lpVtbl: *const $vtbl,
62 }
63 RIDL!{@impl $interface {$(fn $method($($p: $t,)*) -> $rtr,)+}}
64 RIDL!{@uuid $interface $($uuid),+}
65 );
66 (#[uuid($($uuid:expr),+)]
67 interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) {
68 }) => (
69 #[repr(C)]
70 pub struct $vtbl {
71 pub parent: $pvtbl,
72 }
73 #[repr(C)]
74 pub struct $interface {
75 pub lpVtbl: *const $vtbl,
76 }
77 RIDL!{@deref $interface $pinterface}
78 RIDL!{@uuid $interface $($uuid),+}
79 );
80 (#[uuid($($uuid:expr),+)]
81 interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) {$(
82 fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty,
83 )+}) => (
84 #[repr(C)]
85 pub struct $vtbl {
86 pub parent: $pvtbl,
87 $(pub $method: unsafe extern "system" fn(
88 This: *mut $interface,
89 $($p: $t,)*
90 ) -> $rtr,)+
91 }
92 #[repr(C)]
93 pub struct $interface {
94 pub lpVtbl: *const $vtbl,
95 }
96 RIDL!{@impl $interface {$(fn $method($($p: $t,)*) -> $rtr,)+}}
97 RIDL!{@deref $interface $pinterface}
98 RIDL!{@uuid $interface $($uuid),+}
99 );
100 (@deref $interface:ident $pinterface:ident) => (
101 impl ::std::ops::Deref for $interface {
102 type Target = $pinterface;
103 #[inline]
104 fn deref(&self) -> &$pinterface {
105 unsafe { &*(self as *const Self).cast() }
106 }
107 }
108 );
109 (@impl $interface:ident {$(
110 fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty,
111 )+}) => (
112 impl $interface {
113 $(#[inline] pub unsafe fn $method(&self, $($p: $t,)*) -> $rtr {
114 ((*self.lpVtbl).$method)(
115 (self as *const Self).cast_mut(),
116 $($p,)*
117 )
118 })+
119 }
120 );
121 (@uuid $interface:ident
122 $l:expr, $w1:expr, $w2:expr,
123 $b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr
124 ) => (
125 impl $crate::winapi::Interface for $interface {
126 #[inline]
127 fn uuidof() -> $crate::winapi::GUID {
128 $crate::winapi::GUID {
129 data1: $l,
130 data2: $w1,
131 data3: $w2,
132 data4: [$b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8],
133 }
134 }
135 }
136 );
137 }
138
139 RIDL! {#[uuid(0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)]
140 interface IUnknown(IUnknownVtbl) {
141 fn QueryInterface(
142 riid: REFIID,
143 ppvObject: *mut *mut core::ffi::c_void,
144 ) -> HRESULT,
145 fn AddRef() -> ULONG,
146 fn Release() -> ULONG,
147 }}