#winapi #windows-installer

msica

Rust for Windows Installer Custom Actions

5 releases (3 breaking)

0.4.1 Jun 18, 2024
0.4.0 Feb 17, 2024
0.3.0 Oct 17, 2022
0.2.0 Aug 17, 2022
0.1.0 Aug 4, 2022

#50 in Windows APIs

Download history 95/week @ 2024-06-22 37/week @ 2024-06-29 29/week @ 2024-07-06 57/week @ 2024-07-13 70/week @ 2024-07-20 166/week @ 2024-07-27 119/week @ 2024-08-03 78/week @ 2024-08-10 29/week @ 2024-08-17 5/week @ 2024-08-24 36/week @ 2024-08-31 9/week @ 2024-09-07 42/week @ 2024-09-14 38/week @ 2024-09-21 15/week @ 2024-09-28 3/week @ 2024-10-05

98 downloads per month

MIT license

51KB
926 lines

Rust for Windows Installer Custom Actions

latest version build status

Writing custom actions for Windows Installer (MSI) can be difficult enough already, but using Rust can help mitigate some potential issues concerning memory and handle leaks.

These APIs roughly mimic the Windows Installer automation interface for those APIs that can be called in immediate and deferred custom actions.

Example

You can define custom actions in Rust using its foreign function interface like:

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,
    }
}

Using nightly feature

If you enable the nightly feature and use the nightly toolchain, you can use the question mark operator (?) to propagate errors:

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
}

License

This project is licensed under the MIT license.

No runtime deps

Features