initialize COM in app_creator instead of local to module
This commit is contained in:
@@ -6,10 +6,7 @@ use windows::{
|
|||||||
INetFwPolicy2, INetFwRule, NET_FW_ACTION_BLOCK, NET_FW_IP_PROTOCOL_ANY,
|
INetFwPolicy2, INetFwRule, NET_FW_ACTION_BLOCK, NET_FW_IP_PROTOCOL_ANY,
|
||||||
NET_FW_RULE_DIR_OUT, NetFwPolicy2, NetFwRule,
|
NET_FW_RULE_DIR_OUT, NetFwPolicy2, NetFwRule,
|
||||||
},
|
},
|
||||||
System::Com::{
|
System::Com::{CLSCTX_INPROC_SERVER, CoCreateInstance},
|
||||||
CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED, CoCreateInstance, CoInitializeEx,
|
|
||||||
CoUninitialize,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
core::BSTR,
|
core::BSTR,
|
||||||
};
|
};
|
||||||
@@ -19,7 +16,6 @@ const FILTER_NAME_SAVE_SERVER: &str = "[GTA Tools] Block outbound traffic to Roc
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct GameNetworking {
|
pub struct GameNetworking {
|
||||||
com_initialized: bool,
|
|
||||||
pub blocked: bool,
|
pub blocked: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,15 +27,6 @@ impl Default for GameNetworking {
|
|||||||
} else {
|
} else {
|
||||||
Self::is_exe_blocked().unwrap()
|
Self::is_exe_blocked().unwrap()
|
||||||
},
|
},
|
||||||
com_initialized: unsafe { CoInitializeEx(None, COINIT_MULTITHREADED) }.is_ok(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for GameNetworking {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
if self.com_initialized {
|
|
||||||
unsafe { CoUninitialize() };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,15 @@ use crate::{
|
|||||||
util::{persistent_state::PersistentState, win},
|
util::{persistent_state::PersistentState, win},
|
||||||
};
|
};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
use windows::Win32::System::Com::{COINIT_APARTMENTTHREADED, CoInitializeEx};
|
||||||
|
|
||||||
fn app_creator(
|
fn app_creator(
|
||||||
cc: &eframe::CreationContext<'_>,
|
cc: &eframe::CreationContext<'_>,
|
||||||
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
|
// initialize COM just in case
|
||||||
|
if unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) }.is_err() {
|
||||||
|
log::error!("couldn't initialize COM");
|
||||||
|
}
|
||||||
// initialize App early to modify some things before returning it
|
// initialize App early to modify some things before returning it
|
||||||
let mut app = Box::new(App::default());
|
let mut app = Box::new(App::default());
|
||||||
// load previously selected launch platform & settings from persistent state
|
// load previously selected launch platform & settings from persistent state
|
||||||
|
|||||||
Reference in New Issue
Block a user