Skip to content

Commit

Permalink
Fix MSIHANDLE parameter modification in Rust 1.78.0+ (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachNo authored Jun 17, 2024
1 parent 953eb21 commit b2dde43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ impl Database {
/// [SQL string](https://docs.microsoft.com/windows/win32/msi/sql-syntax).
pub fn open_view(&self, sql: &str) -> Result<View> {
unsafe {
let h = ffi::MSIHANDLE::null();
let mut h = ffi::MSIHANDLE::null();
let sql = CString::new(sql)?;
let ret = ffi::MsiDatabaseOpenView(*self.h, sql.as_ptr(), &h);
let ret = ffi::MsiDatabaseOpenView(*self.h, sql.as_ptr(), &mut h);
if ret != ffi::ERROR_SUCCESS {
return Err(
Error::from_last_error_record().unwrap_or_else(|| Error::from_error_code(ret))
Expand All @@ -34,9 +34,9 @@ impl Database {
/// The field count of the record is the count of primary key columns.
pub fn primary_keys(&self, table: &str) -> Result<Record> {
unsafe {
let h = ffi::MSIHANDLE::null();
let mut h = ffi::MSIHANDLE::null();
let table = CString::new(table)?;
let ret = ffi::MsiDatabaseGetPrimaryKeys(*self.h, table.as_ptr(), &h);
let ret = ffi::MsiDatabaseGetPrimaryKeys(*self.h, table.as_ptr(), &mut h);
if ret != ffi::ERROR_SUCCESS {
return Err(Error::from_error_code(ret));
}
Expand Down
10 changes: 7 additions & 3 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ extern "C" {
pub fn MsiDatabaseGetPrimaryKeys(
hDatabase: MSIHANDLE,
szTableName: LPCSTR,
hRecord: &MSIHANDLE,
hRecord: &mut MSIHANDLE,
) -> u32;

#[link_name = "MsiDatabaseOpenViewA"]
pub fn MsiDatabaseOpenView(hDatabase: MSIHANDLE, szQuery: LPCSTR, phView: &MSIHANDLE) -> u32;
pub fn MsiDatabaseOpenView(
hDatabase: MSIHANDLE,
szQuery: LPCSTR,
phView: &mut MSIHANDLE,
) -> u32;

#[link_name = "MsiDoActionA"]
pub fn MsiDoAction(hInstall: MSIHANDLE, szAction: LPCSTR) -> u32;
Expand Down Expand Up @@ -99,7 +103,7 @@ extern "C" {

pub fn MsiViewExecute(hView: MSIHANDLE, hRecord: MSIHANDLE) -> u32;

pub fn MsiViewFetch(hView: MSIHANDLE, phRecord: &MSIHANDLE) -> u32;
pub fn MsiViewFetch(hView: MSIHANDLE, phRecord: &mut MSIHANDLE) -> u32;

pub fn MsiViewModify(hView: MSIHANDLE, eModifyMode: ModifyMode, hRecord: MSIHANDLE) -> u32;
}
Expand Down
4 changes: 2 additions & 2 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ impl Iterator for View {

fn next(&mut self) -> Option<Self::Item> {
unsafe {
let h = ffi::MSIHANDLE::null();
ffi::MsiViewFetch(*self.h, &h);
let mut h = ffi::MSIHANDLE::null();
ffi::MsiViewFetch(*self.h, &mut h);

if h.is_null() {
return None;
Expand Down

0 comments on commit b2dde43

Please sign in to comment.