[英]How do I allocate space to call GetInterfaceInfo using the windows crate?
[英]How do I initialize a CompositionTarget to null using the Rust Crate for Windows?
具体来说,在以下 Windows CoreApp 代码摘录的 Rust Crate 中初始化 CompositionTarget 成员的正确方法是什么?
#[implement(Windows::ApplicationModel::Core::IFrameworkView)]
struct AppView {
target: CompositionTarget,
}
#[allow(non_snake_case)]
impl AppView {
fn new() -> Self { //
Self {
//target: std::ptr::null_mut(),
//target: CompositionTarget(0),
}
}
fn Initialize(&self, _: &Option<CoreApplicationView>) -> Result<()> {
Ok(())
}
fn Load(&self, _: &HSTRING) -> Result<()> {
Ok(())
}
fn Uninitialize(&self) -> Result<()> {
Ok(())
}
fn Run(&self) -> Result<()> {
let window = CoreWindow::GetForCurrentThread()?;
window.Activate()?;
let dispatcher = window.Dispatcher()?;
dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit)?;
Ok(())
}
fn SetWindow(&self, _: &Option<CoreWindow>) -> Result<()> {
let compositor = Compositor::new()?;
let root = compositor.CreateContainerVisual()?;
//...
Ok(())
}
}
fn main() -> Result<()> {
unsafe {
CoInitializeEx(std::ptr::null_mut(), COINIT_MULTITHREADED)?;
}
let app: IFrameworkViewSource = App().into();
CoreApplication::Run(app)?;
Ok(())
}
Rust 没有null
。 相反,您应该使用Option
:
struct AppView {
target: Option<CompositionTarget>,
}
impl AppView {
fn new() -> Self {
Self {
target: None,
}
}
...
This works well since in the windows
crate a CompositionTarget
cannot be null
, any function that would return a null
value will return an Option::None
or Err(Error::Ok)
instead. 看到这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.