Expand description

Rust for Windows Installer Custom Actions

latest version build status

Writing custom actions for Windows Installer 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::*;

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, you can use the question mark operator (?) to propagate errors:

use msica::*;

#[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);
    CustomActionResult::Succeed
}

License

This project is licensed under the MIT license.

Structs

The database for the current install session.
Errors returned by this crate.
A collection of Field containing strings, integers, and byte streams.
A Windows Installer session passed to custom actions.
The View object represents a result set obtained when processing a query using the OpenView method of the Database object. Before any data can be transferred, the query must be executed using the execute method, passing to it all replaceable parameters designated within the SQL query string.

Enums

A result to return from a custom action.
A field in a Record.
Message types that can be processed by a custom action.
Modify modes passed to View::modify.
Run modes passed to Session::mode.

Functions

Gets the last Windows Installer error for the current process.

Type Definitions

Results returned by this crate.