Jump to content

Problem with MsiOpenDatabaseW


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...