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	ok_to_hrresult(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	.map(|_| queried)
47}
48
49/// [`OleLoadPicturePath`](https://learn.microsoft.com/en-us/windows/win32/api/olectl/nf-olectl-oleloadpicturepath)
50/// function.
51///
52/// The picture must be in BMP (bitmap), JPEG, WMF (metafile), ICO (icon), or
53/// GIF format.
54///
55/// # Related functions
56///
57/// * [`OleLoadPicture`](crate::OleLoadPicture)
58#[must_use]
59pub fn OleLoadPicturePath(path: &str, transparent_color: Option<COLORREF>) -> HrResult<IPicture> {
60	let mut queried = unsafe { IPicture::null() };
61	ok_to_hrresult(unsafe {
62		ffi::OleLoadPicturePath(
63			WString::from_str(path).as_ptr(),
64			std::ptr::null_mut(),
65			0,
66			transparent_color.map_or(0, |c| c.into()),
67			pcvoid(&IPicture::IID),
68			queried.as_mut(),
69		)
70	})
71	.map(|_| queried)
72}
73
74/// [`PSGetNameFromPropertyKey`](https://learn.microsoft.com/en-us/windows/win32/api/propsys/nf-propsys-psgetnamefrompropertykey)
75/// function.
76#[must_use]
77pub fn PSGetNameFromPropertyKey(prop_key: &co::PKEY) -> HrResult<String> {
78	let mut pstr = std::ptr::null_mut::<u16>();
79	ok_to_hrresult(unsafe { ffi::PSGetNameFromPropertyKey(pcvoid(prop_key), &mut pstr) })
80		.map(|_| htaskmem_ptr_to_str(pstr))
81}
82
83/// [`SystemTimeToVariantTime`](https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-systemtimetovarianttime)
84/// function.
85///
86/// Note that this function resolves the time to one second; milliseconds are
87/// ignored.
88///
89/// # Related functions
90///
91/// * [`VariantTimeToSystemTime`](crate::VariantTimeToSystemTime)
92#[must_use]
93pub fn SystemTimeToVariantTime(st: &SYSTEMTIME) -> SysResult<f64> {
94	let mut double = f64::default();
95	bool_to_invalidparm(unsafe { ffi::SystemTimeToVariantTime(pcvoid(st), &mut double) })
96		.map(|_| double)
97}
98
99/// [`VariantTimeToSystemTime`](https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-varianttimetosystemtime)
100/// function.
101///
102/// # Related functions
103///
104/// * [`SystemTimeToVariantTime`](crate::SystemTimeToVariantTime)
105#[must_use]
106pub fn VariantTimeToSystemTime(var_time: f64) -> SysResult<SYSTEMTIME> {
107	let mut st = SYSTEMTIME::default();
108	bool_to_invalidparm(unsafe { ffi::VariantTimeToSystemTime(var_time, pvoid(&mut st)) })
109		.map(|_| st)
110}