From 79c6a36707d0caa4fb3240bc28ebabe98a3826f1 Mon Sep 17 00:00:00 2001 From: "Zach N." Date: Tue, 11 Jun 2024 12:15:20 -0700 Subject: [PATCH] Fix MSIHANDLE parameter modification in Rust 1.78.0+ --- src/database.rs | 8 ++++---- src/ffi.rs | 10 +++++++--- src/view.rs | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/database.rs b/src/database.rs index 0d32222..fb5ffc4 100644 --- a/src/database.rs +++ b/src/database.rs @@ -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 { 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)) @@ -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 { 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)); } diff --git a/src/ffi.rs b/src/ffi.rs index e0dbd88..227efdb 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -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; @@ -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; } diff --git a/src/view.rs b/src/view.rs index dbfea12..f23c8e4 100644 --- a/src/view.rs +++ b/src/view.rs @@ -91,8 +91,8 @@ impl Iterator for View { fn next(&mut self) -> Option { 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;