Sign in to follow this  
Followers 0
archrival

Problem with MsiOpenDatabaseW

4 posts in this topic

I'm trying to implement MsiOpenDatabaseW from msi.dll. I'm not getting a handle that I would expect. The 2nd parameter, $szPersist, is usually used as an IntPtr in other implementations. Depending on the values I pass I receive an 87 (ERROR_INVALID_PARAMETER), 110 (ERROR_OPEN_FAILED) or 1631 (ERROR_CREATE_FAILED).

I would expect this line to work:

Global Const $MSIDBOPEN_READONLY = 0
$phDatabase = _MsiOpenDatabase("c:\users\archrival\desktop\xmlnotepad.msi", $MSIDBOPEN_READONLY)

What actually happens is:

$uRet[0] = 0
$uRet[1] = c:\users\archrival\desktop\xmlnotepad.msi 
$uRet[2] = 0 
$uRet[3] = 0x00000001

Any thoughts?

Func _MsiOpenDatabase($szDatabasePath, $szPersist)
    Local $error = 0
    Local $extended
    Local $phDatabase
    Local $uRet = DllCall($msidll, "UINT", "MsiOpenDatabaseW", "wstr", $szDatabasePath, "wstr", $szPersist, "handle*", $phDatabase)
    If @error Then
        $error = @error
    Else
        _ArrayDisplay($uRet)
        If IsArray($uRet) And UBound(4) Then
            $extended = $uRet[0]
            $phDatabase = $uRet[3]
        EndIf
    EndIf
    Return SetError($error, $extended, $phDatabase)
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

Maybe try

DllCall($msidll, "int", "MsiOpenDatabaseW", "wstr", $szDatabasePath, "int", $szPersist, "handle*", $phDatabase)

I don't get an error and I get a 0x00000001 for the $phDatabase return trying it this way when using $MSIDBOPEN_READONLY (0) value for $szPersist param.

Edited by smashly

Share this post


Link to post
Share on other sites

I forgot mention that I've also tried an int as well as a pointer to a struct containing an int_ptr. The int doesn't return an error but it also doesn't seem to provide a valid handle.

Share this post


Link to post
Share on other sites

I forgot mention that I've also tried an int as well as a pointer to a struct containing an int_ptr. The int doesn't return an error but it also doesn't seem to provide a valid handle.

Perhaps I should have actually tried the returned handle, it works. Oops... I didn't expect 0x00000001 to be valid.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0