winsafe/mf/com_interfaces/
imfattributes.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::guard::*;
6use crate::kernel::privs::*;
7use crate::mf::vts::*;
8use crate::ole::privs::*;
9use crate::prelude::*;
10
11com_interface! { IMFAttributes: "2cd2d921-c447-44a7-a13c-4adabfc247e3";
12	/// [`IMFAttributes`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nn-mfobjects-imfattributes)
13	/// COM interface.
14	///
15	/// Automatically calls
16	/// [`Release`](https://learn.microsoft.com/en-us/windows/win32/api/unknwn/nf-unknwn-iunknown-release)
17	/// when the object goes out of scope.
18}
19
20impl mf_IMFAttributes for IMFAttributes {}
21
22/// This trait is enabled with the `mf` feature, and provides methods for
23/// [`IMFAttributes`](crate::IMFAttributes).
24///
25/// Prefer importing this trait through the prelude:
26///
27/// ```no_run
28/// use winsafe::prelude::*;
29/// ```
30pub trait mf_IMFAttributes: ole_IUnknown {
31	/// [`IMFAttributes::Compare`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-compare)
32	/// method.
33	#[must_use]
34	fn Compare(
35		&self,
36		theirs: &impl mf_IMFAttributes,
37		match_type: co::MF_ATTRIBUTES_MATCH,
38	) -> HrResult<bool> {
39		let mut res = 0;
40		HrRet(unsafe {
41			(vt::<IMFAttributesVT>(self).Compare)(
42				self.ptr(),
43				theirs.ptr(),
44				match_type.raw(),
45				&mut res,
46			)
47		})
48		.to_hrresult()
49		.map(|_| res != 0)
50	}
51
52	/// [`IMFAttributes::CompareItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-compareitem)
53	/// method.
54	#[must_use]
55	fn CompareItem(&self, guid_key: &GUID, value: &PropVariant) -> HrResult<bool> {
56		let mut res = 0;
57		HrRet(unsafe {
58			(vt::<IMFAttributesVT>(self).CompareItem)(
59				self.ptr(),
60				pcvoid(guid_key),
61				pcvoid(&value.to_raw()?),
62				&mut res,
63			)
64		})
65		.to_hrresult()
66		.map(|_| res != 0)
67	}
68
69	/// [`IMFAttributes::CopyAllItems`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-copyallitems)
70	/// method.
71	fn CopyAllItems(&self, dest: &impl mf_IMFAttributes) -> HrResult<()> {
72		HrRet(unsafe { (vt::<IMFAttributesVT>(self).CopyAllItems)(self.ptr(), dest.ptr()) })
73			.to_hrresult()
74	}
75
76	fn_com_noparm! { DeleteAllItems: IMFAttributesVT;
77		/// [`IMFAttributes::DeleteAllItems`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-deleteallitems)
78		/// method.
79	}
80
81	/// [`IMFAttributes::DeleteItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-deleteitem)
82	/// method.
83	fn DeleteItem(&self, guid_key: &GUID) -> HrResult<()> {
84		HrRet(unsafe { (vt::<IMFAttributesVT>(self).DeleteItem)(self.ptr(), pcvoid(guid_key)) })
85			.to_hrresult()
86	}
87
88	/// [`IMFAttributes::GetAllocatedBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getallocatedblob)
89	/// method.
90	///
91	/// Note that this method allocates the buffer twice, whereas
92	/// [`IMFAttributes::GetBlob`](crate::prelude::mf_IMFAttributes::GetBlob)
93	/// allocates only once, thus being more efficient.
94	#[must_use]
95	fn GetAllocatedBlob(&self, guid_key: &GUID) -> HrResult<Vec<u8>> {
96		let mut pbuf = std::ptr::null_mut::<u8>();
97		let mut sz = 0u32;
98
99		HrRet(unsafe {
100			(vt::<IMFAttributesVT>(self).GetAllocatedBlob)(
101				self.ptr(),
102				pcvoid(guid_key),
103				&mut pbuf,
104				&mut sz,
105			)
106		})
107		.to_hrresult()
108		.map(|_| {
109			let raw = unsafe { CoTaskMemFreeGuard::new(pbuf as *mut _, sz as _) };
110			raw.as_slice().to_vec()
111		})
112	}
113
114	/// [`IMFAttributes::GetAllocatedString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getallocatedstring)
115	/// method.
116	///
117	/// Note that this method allocates the buffer twice, whereas
118	/// [`IMFAttributes::GetString`](crate::prelude::mf_IMFAttributes::GetString)
119	/// allocates only once, thus being more efficient.
120	#[must_use]
121	fn GetAllocatedString(&self, guid_key: &GUID) -> HrResult<String> {
122		let mut pstr = std::ptr::null_mut::<u16>();
123		let mut nchars = 0u32;
124
125		HrRet(unsafe {
126			(vt::<IMFAttributesVT>(self).GetAllocatedString)(
127				self.ptr(),
128				pcvoid(guid_key),
129				&mut pstr,
130				&mut nchars,
131			)
132		})
133		.to_hrresult()
134		.map(|_| htaskmem_ptr_to_str(pstr))
135	}
136
137	/// [`IMFAttributes::GetBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getblob)
138	/// method.
139	///
140	/// Calls
141	/// [`IMFAttributes::GetBlobSize`](crate::prelude::mf_IMFAttributes::GetBlobSize)
142	/// to alloc the buffer.
143	#[must_use]
144	fn GetBlob(&self, guid_key: &GUID) -> HrResult<Vec<u8>> {
145		let sz = self.GetBlobSize(guid_key)?;
146		let mut buf = vec![0u8; sz as _];
147
148		HrRet(unsafe {
149			(vt::<IMFAttributesVT>(self).GetBlob)(
150				self.ptr(),
151				pcvoid(guid_key),
152				buf.as_mut_ptr(),
153				sz,
154				std::ptr::null_mut(),
155			)
156		})
157		.to_hrresult()
158		.map(|_| buf)
159	}
160
161	/// [`IMFAttributes::GetBlobSize`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getblobsize)
162	/// method.
163	#[must_use]
164	fn GetBlobSize(&self, guid_key: &GUID) -> HrResult<u32> {
165		let mut sz = 0u32;
166		HrRet(unsafe {
167			(vt::<IMFAttributesVT>(self).GetBlobSize)(self.ptr(), pcvoid(guid_key), &mut sz)
168		})
169		.to_hrresult()
170		.map(|_| sz)
171	}
172
173	/// [`IMFAttributes::GetCount`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getcount)
174	/// method.
175	#[must_use]
176	fn GetCount(&self) -> HrResult<u32> {
177		let mut count = 0u32;
178		HrRet(unsafe { (vt::<IMFAttributesVT>(self).GetCount)(self.ptr(), &mut count) })
179			.to_hrresult()
180			.map(|_| count)
181	}
182
183	/// [`IMFAttributes::GetDouble`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getdouble)
184	/// method.
185	#[must_use]
186	fn GetDouble(&self, guid_key: &GUID) -> HrResult<f64> {
187		let mut value = f64::default();
188		HrRet(unsafe {
189			(vt::<IMFAttributesVT>(self).GetDouble)(self.ptr(), pcvoid(guid_key), &mut value)
190		})
191		.to_hrresult()
192		.map(|_| value)
193	}
194
195	/// [`IMFAttributes::GetGUID`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getguid)
196	/// method.
197	#[must_use]
198	fn GetGUID(&self, guid_key: &GUID) -> HrResult<GUID> {
199		let mut value = GUID::default();
200		HrRet(unsafe {
201			(vt::<IMFAttributesVT>(self).GetGUID)(self.ptr(), pcvoid(guid_key), pvoid(&mut value))
202		})
203		.to_hrresult()
204		.map(|_| value)
205	}
206
207	/// [`IMFAttributes::GetItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitem)
208	/// method.
209	#[must_use]
210	fn GetItem(&self, guid_key: &GUID) -> HrResult<PropVariant> {
211		let mut value = PROPVARIANT::default();
212		HrRet(unsafe {
213			(vt::<IMFAttributesVT>(self).GetItem)(self.ptr(), pcvoid(guid_key), pvoid(&mut value))
214		})
215		.to_hrresult()?;
216		PropVariant::from_raw(&value)
217	}
218
219	/// [`IMFAttributes::GetItemByIndex`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitembyindex)
220	/// method.
221	#[must_use]
222	fn GetItemByIndex(&self, index: u32) -> HrResult<(GUID, PropVariant)> {
223		let mut guid = GUID::default();
224		let mut value = PROPVARIANT::default();
225
226		HrRet(unsafe {
227			(vt::<IMFAttributesVT>(self).GetItemByIndex)(
228				self.ptr(),
229				index,
230				pvoid(&mut guid),
231				pvoid(&mut value),
232			)
233		})
234		.to_hrresult()?;
235		Ok((guid, PropVariant::from_raw(&value)?))
236	}
237
238	/// [`IMFAttributes::GetItemType`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getitemtype)
239	/// method.
240	#[must_use]
241	fn GetItemType(&self, guid_key: &GUID) -> HrResult<co::MF_ATTRIBUTE> {
242		let mut ty = co::MF_ATTRIBUTE::default();
243		HrRet(unsafe {
244			(vt::<IMFAttributesVT>(self).GetItemType)(self.ptr(), pcvoid(guid_key), ty.as_mut())
245		})
246		.to_hrresult()
247		.map(|_| ty)
248	}
249
250	/// [`IMFAttributes::GetString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getstring)
251	/// method.
252	///
253	/// Calls
254	/// [`IMFAttributes::GetStringLength`](crate::prelude::mf_IMFAttributes::GetStringLength)
255	/// to alloc the buffer.
256	#[must_use]
257	fn GetString(&self, guid_key: &GUID) -> HrResult<String> {
258		let len = self.GetStringLength(guid_key)? + 1;
259		let mut buf = WString::new_alloc_buf(len as _);
260
261		HrRet(unsafe {
262			(vt::<IMFAttributesVT>(self).GetString)(
263				self.ptr(),
264				pcvoid(guid_key),
265				buf.as_mut_ptr(),
266				len,
267				std::ptr::null_mut(),
268			)
269		})
270		.to_hrresult()
271		.map(|_| buf.to_string())
272	}
273
274	/// [`IMFAttributes::GetStringLength`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getstringlength)
275	/// method.
276	#[must_use]
277	fn GetStringLength(&self, guid_key: &GUID) -> HrResult<u32> {
278		let mut len = 0u32;
279		HrRet(unsafe {
280			(vt::<IMFAttributesVT>(self).GetStringLength)(self.ptr(), pcvoid(guid_key), &mut len)
281		})
282		.to_hrresult()
283		.map(|_| len)
284	}
285
286	/// [`IMFAttributes::GetUINT32`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getuint32)
287	/// method.
288	fn GetUINT32(&self, guid_key: &GUID) -> HrResult<u32> {
289		let mut value = 0u32;
290		HrRet(unsafe {
291			(vt::<IMFAttributesVT>(self).GetUINT32)(self.ptr(), pcvoid(guid_key), &mut value)
292		})
293		.to_hrresult()
294		.map(|_| value)
295	}
296
297	/// [`IMFAttributes::GetUINT64`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getuint64)
298	/// method.
299	fn GetUINT64(&self, guid_key: &GUID) -> HrResult<u64> {
300		let mut value = 0u64;
301		HrRet(unsafe {
302			(vt::<IMFAttributesVT>(self).GetUINT64)(self.ptr(), pcvoid(guid_key), &mut value)
303		})
304		.to_hrresult()
305		.map(|_| value)
306	}
307
308	/// [`IMFAttributes::GetUnknown`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-getunknown)
309	/// method.
310	#[must_use]
311	fn GetUnknown<T>(&self, guid_key: &GUID) -> HrResult<T>
312	where
313		T: ole_IUnknown,
314	{
315		let mut queried = unsafe { T::null() };
316		HrRet(unsafe {
317			(vt::<IMFAttributesVT>(self).GetUnknown)(
318				self.ptr(),
319				pcvoid(guid_key),
320				pcvoid(&T::IID),
321				queried.as_mut(),
322			)
323		})
324		.to_hrresult()
325		.map(|_| queried)
326	}
327
328	fn_com_noparm! { LockStore: IMFAttributesVT;
329		/// [`IMFAttributes::LockStore`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-lockstore)
330		/// method.
331	}
332
333	/// [`IMFAttributes::SetBlob`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setblob)
334	/// method.
335	fn SetBlob(&self, guid_key: &GUID, buf: &[u8]) -> HrResult<()> {
336		HrRet(unsafe {
337			(vt::<IMFAttributesVT>(self).SetBlob)(
338				self.ptr(),
339				pcvoid(guid_key),
340				vec_ptr(buf),
341				buf.len() as _,
342			)
343		})
344		.to_hrresult()
345	}
346
347	/// [`IMFAttributes::SetDouble`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setdouble)
348	/// method.
349	fn SetDouble(&self, guid_key: &GUID, value: f64) -> HrResult<()> {
350		HrRet(unsafe {
351			(vt::<IMFAttributesVT>(self).SetDouble)(self.ptr(), pcvoid(guid_key), value)
352		})
353		.to_hrresult()
354	}
355
356	/// [`IMFAttributes::SetGUID`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setguid)
357	/// method.
358	fn SetGUID(&self, guid_key: &GUID, value: &GUID) -> HrResult<()> {
359		HrRet(unsafe {
360			(vt::<IMFAttributesVT>(self).SetGUID)(self.ptr(), pcvoid(guid_key), pcvoid(value))
361		})
362		.to_hrresult()
363	}
364
365	/// [`IMFAttributes::SetItem`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setitem)
366	/// method.
367	fn SetItem(&self, guid_key: &GUID, value: &PropVariant) -> HrResult<()> {
368		HrRet(unsafe {
369			(vt::<IMFAttributesVT>(self).SetItem)(
370				self.ptr(),
371				pcvoid(guid_key),
372				pcvoid(&value.to_raw()?),
373			)
374		})
375		.to_hrresult()
376	}
377
378	/// [`IMFAttributes::SetString`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setstring)
379	/// method.
380	fn SetString(&self, guid_key: &GUID, value: &str) -> HrResult<()> {
381		HrRet(unsafe {
382			(vt::<IMFAttributesVT>(self).SetString)(
383				self.ptr(),
384				pcvoid(guid_key),
385				WString::from_str(value).as_ptr(),
386			)
387		})
388		.to_hrresult()
389	}
390
391	/// [`IMFAttributes::SetUINT32`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setuint32)
392	/// method.
393	fn SetUINT32(&self, guid_key: &GUID, value: u32) -> HrResult<()> {
394		HrRet(unsafe {
395			(vt::<IMFAttributesVT>(self).SetUINT32)(self.ptr(), pcvoid(guid_key), value)
396		})
397		.to_hrresult()
398	}
399
400	/// [`IMFAttributes::SetUINT64`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setuint64)
401	/// method.
402	fn SetUINT64(&self, guid_key: &GUID, value: u64) -> HrResult<()> {
403		HrRet(unsafe {
404			(vt::<IMFAttributesVT>(self).SetUINT64)(self.ptr(), pcvoid(guid_key), value)
405		})
406		.to_hrresult()
407	}
408
409	/// [`IMFAttributes::SetUnknown`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-setunknown)
410	/// method.
411	fn SetUnknown(&self, guid_key: &GUID, value: &impl ole_IUnknown) -> HrResult<()> {
412		HrRet(unsafe {
413			(vt::<IMFAttributesVT>(self).SetUnknown)(self.ptr(), pcvoid(guid_key), value.ptr())
414		})
415		.to_hrresult()
416	}
417
418	fn_com_noparm! { UnlockStore: IMFAttributesVT;
419		/// [`IMFAttributes::UnlockStore`](https://learn.microsoft.com/en-us/windows/win32/api/mfobjects/nf-mfobjects-imfattributes-unlockstore)
420		/// method.
421	}
422}