Debian Codegraph @

.cargo/vendor/cc/src/windows/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 use std::os::raw;
11
12 pub type wchar_t = u16;
13
14 pub use crate::windows::windows_sys::{FILETIME, GUID, HRESULT, SAFEARRAY};
15
16 pub type REFIID = *const IID;
17 pub type IID = GUID;
18 pub type ULONG = raw::c_ulong;
19 pub type DWORD = u32;
20 pub type LPFILETIME = *mut FILETIME;
21 pub type OLECHAR = WCHAR;
22 pub type WCHAR = wchar_t;
23 pub type LPCOLESTR = *const OLECHAR;
24 pub type LCID = DWORD;
25 pub type LPCWSTR = *const WCHAR;
26 pub type PULONGLONG = *mut ULONGLONG;
27 pub type ULONGLONG = u64;
28
29 pub trait Interface {
30 fn uuidof() -> GUID;
31 }
32
33 pub type LPSAFEARRAY = *mut SAFEARRAY;
34
35 macro_rules! DEFINE_GUID {
36 (
37 $name:ident, $l:expr, $w1:expr, $w2:expr,
38 $b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr
39 ) => {
40 pub const $name: $crate::windows::winapi::GUID = $crate::windows::winapi::GUID {
41 data1: $l,
42 data2: $w1,
43 data3: $w2,
44 data4: [$b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8],
45 };
46 };
47 }
48
49 macro_rules! RIDL {
50 (#[uuid($($uuid:expr),+)]
51 interface $interface:ident ($vtbl:ident) {$(
52 fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty,
53 )+}) => (
54 #[repr(C)]
55 pub struct $vtbl {
56 $(pub $method: unsafe extern "system" fn(
57 This: *mut $interface,
58 $($p: $t),*
59 ) -> $rtr,)+
60 }
61 #[repr(C)]
62 pub struct $interface {
63 pub lpVtbl: *const $vtbl,
64 }
65 RIDL!{@impl $interface {$(fn $method($($p: $t,)*) -> $rtr,)+}}
66 RIDL!{@uuid $interface $($uuid),+}
67 );
68 (#[uuid($($uuid:expr),+)]
69 interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) {
70 }) => (
71 #[repr(C)]
72 pub struct $vtbl {
73 pub parent: $pvtbl,
74 }
75 #[repr(C)]
76 pub struct $interface {
77 pub lpVtbl: *const $vtbl,
78 }
79 RIDL!{@deref $interface $pinterface}
80 RIDL!{@uuid $interface $($uuid),+}
81 );
82 (#[uuid($($uuid:expr),+)]
83 interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) {$(
84 fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty,
85 )+}) => (
86 #[repr(C)]
87 pub struct $vtbl {
88 pub parent: $pvtbl,
89 $(pub $method: unsafe extern "system" fn(
90 This: *mut $interface,
91 $($p: $t,)*
92 ) -> $rtr,)+
93 }
94 #[repr(C)]
95 pub struct $interface {
96 pub lpVtbl: *const $vtbl,
97 }
98 RIDL!{@impl $interface {$(fn $method($($p: $t,)*) -> $rtr,)+}}
99 RIDL!{@deref $interface $pinterface}
100 RIDL!{@uuid $interface $($uuid),+}
101 );
102 (@deref $interface:ident $pinterface:ident) => (
103 impl ::std::ops::Deref for $interface {
104 type Target = $pinterface;
105 #[inline]
106 fn deref(&self) -> &$pinterface {
107 unsafe { &*(self as *const $interface as *const $pinterface) }
108 }
109 }
110 );
111 (@impl $interface:ident {$(
112 fn $method:ident($($p:ident : $t:ty,)*) -> $rtr:ty,
113 )+}) => (
114 impl $interface {
115 $(#[inline] pub unsafe fn $method(&self, $($p: $t,)*) -> $rtr {
116 ((*self.lpVtbl).$method)(self as *const _ as *mut _, $($p,)*)
117 })+
118 }
119 );
120 (@uuid $interface:ident
121 $l:expr, $w1:expr, $w2:expr,
122 $b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr
123 ) => (
124 impl $crate::windows::winapi::Interface for $interface {
125 #[inline]
126 fn uuidof() -> $crate::windows::winapi::GUID {
127 $crate::windows::winapi::GUID {
128 data1: $l,
129 data2: $w1,
130 data3: $w2,
131 data4: [$b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8],
132 }
133 }
134 }
135 );
136 }
137
138 RIDL! {#[uuid(0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)]
139 interface IUnknown(IUnknownVtbl) {
140 fn QueryInterface(
141 riid: REFIID,
142 ppvObject: *mut *mut raw::c_void,
143 ) -> HRESULT,
144 fn AddRef() -> ULONG,
145 fn Release() -> ULONG,
146 }}