winsafe\oleaut/
funcs.rs

1#![allow(non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::kernel::privs::*;
6use crate::ole::privs::*;
7use crate::oleaut::ffi;
8use crate::prelude::*;
9
10/// [`OleLoadPicture`](https://learn.microsoft.com/en-us/windows/win32/api/olectl/nf-olectl-oleloadpicture)
11/// function.
12///
13/// # Examples
14///
15/// Parsing an image from raw data:
16///
17/// ```no_run
18/// use winsafe::{self as w, prelude::*};
19///
20/// let stream: w::IStream; // initialized somewhere
21/// # let stream = unsafe { w::IStream::null() };
22///
23/// let picture = w::OleLoadPicture(&stream, None, true)?;
24/// # w::HrResult::Ok(())
25/// ```
26///
27/// # Related functions
28///
29/// * [`OleLoadPicturePath`](crate::OleLoadPicturePath)
30#[must_use]
31pub fn OleLoadPicture(
32	stream: &impl ole_IStream,
33	size: Option<u32>,
34	keep_original_format: bool,
35) -> HrResult<IPicture> {
36	let mut queried = unsafe { IPicture::null() };
37	HrRet(unsafe {
38		ffi::OleLoadPicture(
39			stream.ptr() as _,
40			size.unwrap_or_default() as _,
41			!keep_original_format as _, // note: reversed
42			pcvoid(&IPicture::IID),
43			queried.as_mut(),
44		)
45	})
46	.to_hrresult()
47	.map(|_| queried)
48}
49
50/// [`OleLoadPicturePath`](https://learn.microsoft.com/en-us/windows/win32/api/olectl/nf-olectl-oleloadpicturepath)
51/// function.
52///
53/// The picture must be in BMP (bitmap), JPEG, WMF (metafile), ICO (icon), or
54/// GIF format.
55///
56/// # Related functions
57///
58/// * [`OleLoadPicture`](crate::OleLoadPicture)
59#[must_use]
60pub fn OleLoadPicturePath(path: &str, transparent_color: Option<COLORREF>) -> HrResult<IPicture> {
61	let mut queried = unsafe { IPicture::null() };
62	HrRet(unsafe {
63		ffi::OleLoadPicturePath(
64			WString::from_str(path).as_ptr(),
65			std::ptr::null_mut(),
66			0,
67			transparent_color.map_or(0, |c| c.into()),
68			pcvoid(&IPicture::IID),
69			queried.as_mut(),
70		)
71	})
72	.to_hrresult()
73	.map(|_| queried)
74}
75
76/// [`PSGetNameFromPropertyKey`](https://learn.microsoft.com/en-us/windows/win32/api/propsys/nf-propsys-psgetnamefrompropertykey)
77/// function.
78#[must_use]
79pub fn PSGetNameFromPropertyKey(prop_key: &co::PKEY) -> HrResult<String> {
80	let mut pstr = std::ptr::null_mut::<u16>();
81	HrRet(unsafe { ffi::PSGetNameFromPropertyKey(pcvoid(prop_key), &mut pstr) })
82		.to_hrresult()
83		.map(|_| htaskmem_ptr_to_str(pstr))
84}
85
86/// [`SystemTimeToVariantTime`](https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-systemtimetovarianttime)
87/// function.
88///
89/// Note that this function resolves the time to one second; milliseconds are
90/// ignored.
91///
92/// # Related functions
93///
94/// * [`VariantTimeToSystemTime`](crate::VariantTimeToSystemTime)
95#[must_use]
96pub fn SystemTimeToVariantTime(st: &SYSTEMTIME) -> SysResult<f64> {
97	let mut double = f64::default();
98	BoolRet(unsafe { ffi::SystemTimeToVariantTime(pcvoid(st), &mut double) })
99		.to_invalidparm()
100		.map(|_| double)
101}
102
103/// [`VariantTimeToSystemTime`](https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-varianttimetosystemtime)
104/// function.
105///
106/// # Related functions
107///
108/// * [`SystemTimeToVariantTime`](crate::SystemTimeToVariantTime)
109#[must_use]
110pub fn VariantTimeToSystemTime(var_time: f64) -> SysResult<SYSTEMTIME> {
111	let mut st = SYSTEMTIME::default();
112	BoolRet(unsafe { ffi::VariantTimeToSystemTime(var_time, pvoid(&mut st)) })
113		.to_invalidparm()
114		.map(|_| st)
115}