Installer :: OpenDatabase () throws type error with msiOpenDatabaseModeTransact
The following code throws error hr = 0x80020005 (wrong type).
#import <msi.dll>
using namespace WindowsInstaller;
main()
{
::CoInitialize(NULL);
InstallerPtr pInstaller("WindowsInstaller.Installer");
DatabasePtr pDB = pInstaller->OpenDatabase(
"c:\\foo\\bar.msi",
msiOpenDatabaseModeTransact);
}
I think the reason is because behind the scene there is MsiOpenDatabase () which take LPCTSTR as the second argument. This second argument can be MSIDBOPEN_TRANSACT, which is defined
#define MSIDBOPEN_TRANSACT (LPCTSTR)1
I don't know if it is possible to give a variant with a good inner type as the second argument. The constructor _variant_t
does a lot of checks, so I can't mask an int into a char * that easily.
Has anyone tried using this method in C ++?
Edit:
My version of msi.dll is 3.1.4000.2805, my system is XP SP 2 and the code should work on any computer with XP or Vista.
links to MSDN articles are welcome.
On the same computer, calling the low-level equivalent:
MsiOpenDatabase("c:\\foo\\bar.msi", MSIDBOPEN_TRANSACT);
works great.
source to share
I finally got an answer on the msdn forums
DatabasePtr pDB = pInstaller->OpenDatabase(
"c:\\foo\\bar.msi",
(long)msiOpenDatabaseModeTransact);
source to share
MSDN says that OpenDatabase is available from MSI 4.0 onwards, transactions generally from MSI 4.5 onwards. Just a guess, but could it be that your MSI is out of date? I once had a mysterious problem with an outdated MSI version.
source to share