5 个版本 (3 个破坏性更新)
0.4.1 | 2024年6月18日 |
---|---|
0.4.0 | 2024年2月17日 |
0.3.0 | 2022年10月17日 |
0.2.0 | 2022年8月17日 |
0.1.0 | 2022年8月4日 |
#3 在 #leak
每月459次下载
51KB
926 行
Rust 用于 Windows 安装程序自定义操作
编写 自定义操作 以用于 Windows 安装程序(MSI)已经足够困难,但使用 Rust 可以帮助减轻一些关于内存和处理泄露的潜在问题。
这些 API 大约模仿了 Windows 安装程序的 自动化接口,适用于可以立即和延迟调用的 API。
示例
您可以使用 Rust 的 外部函数接口定义自定义操作,如下所示
use msica::prelude::*;
const ERROR_SUCCESS: u32 = 0;
const ERROR_INSTALL_FAILURE: u32 = 1603;
#[no_mangle]
pub extern "C" fn MyCustomAction(session: Session) -> u32 {
match Record::with_fields(
Some("this is [1] [2]"),
vec![
Field::IntegerData(1),
Field::StringData("example".to_owned()),
],
) {
Ok(record) => {
session.message(MessageType::User, &record);
ERROR_SUCCESS
}
_ => ERROR_INSTALL_FAILURE,
}
}
使用夜间功能
如果您启用了 nightly
功能并使用夜间工具链,则可以使用问号运算符 (?
) 来传播错误
use msica::prelude::*;
#[no_mangle]
pub extern "C" fn MyCustomAction(session: Session) -> CustomActionResult {
let record = Record::with_fields(
Some("this is [1] [2]"),
vec![Field::IntegerData(1), Field::StringData("example".to_owned())],
)?;
session.message(MessageType::User, &record);
Success
}
许可证
该项目根据 MIT 许可证 进行许可。