# wincom
A lightweight Rust wrapper for Windows COM [`IDispatch`] automation.
`wincom` focuses on the late-binding path that most scripting hosts
(AutoCAD, CorelDRAW, Office, …) expose. It provides:
- **`ComObject`** — wraps an `IDispatch` and offers name-based property
reads/writes and method invocation.
- **`Variant`** — a RAII wrapper over `VARIANT` that calls `VariantClear`
on drop, eliminating a common source of leaks.
- **Conversions** — `i16/i32/i64`, `u8/u16/u32/u64`, `f64`, `bool`,
`String`, and `Vec<f64>` in both directions.
## Example
```rust
use wincom::{ComObject, Variant};
fn main() -> wincom::Result<()> {
// Bind to a running CorelDRAW instance.
let app = ComObject::new_from_active("CorelDRAW.Application")?;
// Read a property.
let version: String = app.get_property("Version")?.to_string()?;
println!("CorelDRAW version: {version}");
// Write a property.
app.set_property("Visible", vec![Variant::from_bool(true)])?;
// Call a method.
let _doc = app.invoke_method("AddDocument", Vec::new())?;
Ok(())
}
```
COM must already be initialized on the calling thread:
```rust
use windows::Win32::System::Com;
unsafe { Com::CoInitialize(None).ok()? };
// ... use ComObject ...
unsafe { Com::CoUninitialize() };
```
## Platform
Windows only. On other platforms the crate compiles to an empty library
(`#![cfg(windows)]`).
## Threading
`ComObject` is **not** `Send` or `Sync`. COM objects are apartment-bound;
marshal them explicitly if you need cross-thread access.
## Minimum supported Rust version
Rust **1.71** or later.
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
- MIT license ([LICENSE-MIT](LICENSE-MIT))
at your option.
[`IDispatch`]: https://learn.microsoft.com/en-us/windows/win32/api/oaidl/nn-oaidl-idispatch