File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ extern "C" {
2525 #[ link_name = "MsiDoActionA" ]
2626 pub fn MsiDoAction ( hInstall : MSIHANDLE , szAction : LPCSTR ) -> u32 ;
2727
28+ pub fn MsiGetLastErrorRecord ( ) -> MSIHANDLE ;
29+
2830 pub fn MsiGetMode ( hInstall : MSIHANDLE , eRunMode : RunMode ) -> BOOL ;
2931
3032 #[ link_name = "MsiGetPropertyA" ]
Original file line number Diff line number Diff line change @@ -71,6 +71,26 @@ pub enum RunMode {
7171 Commit = 18 ,
7272}
7373
74+ /// Gets the last Windows Installer error for the current process.
75+ ///
76+ /// # Example
77+ ///
78+ /// ```
79+ /// use msica::*;
80+ ///
81+ /// if let Some(error) = last_error_record() {
82+ /// println!("last error: {}", error.format_text());
83+ /// }
84+ /// ```
85+ pub fn last_error_record ( ) -> Option < Record > {
86+ unsafe {
87+ match ffi:: MsiGetLastErrorRecord ( ) {
88+ h if !h. is_null ( ) => Some ( h. into ( ) ) ,
89+ _ => None ,
90+ }
91+ }
92+ }
93+
7494/// A Windows Installer handle. This handle is not automatically closed.
7595#[ derive( Clone , Copy ) ]
7696#[ repr( transparent) ]
@@ -84,6 +104,10 @@ impl MSIHANDLE {
84104 fn to_owned ( & self ) -> PMSIHANDLE {
85105 PMSIHANDLE ( * self )
86106 }
107+
108+ fn is_null ( & self ) -> bool {
109+ self . 0 == 0
110+ }
87111}
88112
89113impl From < u32 > for MSIHANDLE {
Original file line number Diff line number Diff line change @@ -263,6 +263,12 @@ impl Deref for Record {
263263 }
264264}
265265
266+ impl From < MSIHANDLE > for Record {
267+ fn from ( h : MSIHANDLE ) -> Self {
268+ Record { h : h. to_owned ( ) }
269+ }
270+ }
271+
266272impl From < & str > for Record {
267273 fn from ( s : & str ) -> Self {
268274 unsafe {
You can’t perform that action at this time.
0 commit comments