1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use ;
/// An "IN" param to a Windows API.
///
/// In the Windows API, "IN" params are optional params that are borrowed for the lifetime of the function call.
///
/// Therefore, `InParam<'a, T>` is essentially, an optional `&'a T` (where `'a` is the lifetime of the function call)
/// that has the right in-memory layout to passed to a Windows API.
///
/// # Usage
///
/// Many functions in the `windows` crate have signatures similar to the following:
///
/// ```ignore
/// fn SomeFunction<'a, P: Into<InParam<'a, IUnknown>>>(iunknown: P);
/// ```
///
/// This signature allows the parameter `iunknown` to passed any value that implements `Into<InParam<'a, IUnknown>>`.
/// In other words, anything that can be turned into an `InParam<'a, IUnknown>` can be used as an argument to this function.
///
/// So, what can be turned into an `InParam`?
///
/// Generally, if this is safe to do, the `windows` crate provides an implementation allowing you to pass the item. This means,
/// you should be able to pass anything that is logically equivalent to an `IUnknown` into `SomeFunction`.
///
/// Here are the typical things that can be converted into an `InParam<'a, T>`:
///
/// * References to a value of type `T` (i.e., `&'a T`).
/// * Anything that can be turned into a `&'a T`.
/// * For example, many COM interfaces have such conversions to parent interfaces. For example, if a function requires an `InParam<'a, IUnknown>`,
/// you can pass a `&'a IInspectable` since `IInspectable` inherits from `IUnknown`.
/// * `None` - because `InParams`s are always optional
/// * Children classes in a WinRT hierarchy.
/// * For example, `CompositionProjectedShadowCaster` has a method called `SetBrush`. This method takes any type that implements `Into<InParam<'a, CompositionBrush>>`.
/// This allows you to pass a `&CompositionBrush` but also children classes like `CompositionColorBrush`.
///
/// # What is the reason for `InParam` existing?
///
/// `InParams`s can be thought of much kind of like an `Cow<'a, Option<T>>` - i.e., an optional value that might be owned or might be borrowed.
/// The reason `InParam` must be used instead of `Cow<'a, Option<T>>` is because for FFI calls to work, we need to be very careful about the in-memory
/// layout of the parameter. `InParam` takes care of turning the value into the proper in-memory layout that the FFI call expects.
///
/// `InParam`s are composed of either an owned type or a `Borrowed<'a, T>`. If you want to know more about how the types line up at the abi layer,
/// read the docs for `Borrowed` and for `Abi`.
/// This allows us to represent `InParam` as an enum but keep that as an implementation detail
primitive_types!;