use crate::com::{SafeDispatch, SafeVariant};
use crate::errors::SageResult;
use windows::Win32::System::Com::IDispatch;
pub struct ErrorCollection {
pub dispatch: IDispatch,
}
impl ErrorCollection {
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
pub fn count(&self) -> SageResult<i32> {
self.dispatch().get_property_by_name("Count")?.to_i32()
}
pub fn item(&self, index: i32) -> SageResult<FailInfo> {
let index_variant = SafeVariant::I4(index);
let result = self
.dispatch()
.call_method_by_name("Item", &[index_variant])?;
let dispatch = result.to_dispatch()?;
Ok(FailInfo { dispatch })
}
}
pub struct FailInfo {
pub dispatch: IDispatch,
}
impl FailInfo {
fn dispatch(&self) -> SafeDispatch<'_> {
SafeDispatch::new(&self.dispatch)
}
pub fn error_code(&self) -> SageResult<i32> {
self.dispatch().get_property_by_name("ErrorCode")?.to_i32()
}
pub fn indice(&self) -> SageResult<i32> {
self.dispatch().get_property_by_name("Indice")?.to_i32()
}
pub fn text(&self) -> SageResult<String> {
self.dispatch().get_property_by_name("Text")?.to_string()
}
}