Jump to content

This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.

Using MSI via COM in C++

2 replies to this topic


  • Members
  • 6 posts

Posted 20 April 2006 - 17:51

Okay, so I'm trying to write a simple MFC app that allows a novice user to open an MSI package, and view some properties, ultimately for the purpose of changing some text strings.

I'm using COM and after I create my Installer object, I'm able to do some basic stuff such as InstallerPtr->GetVersion() (retrieves version of Windows Installer). Where my problem lies is in opening and actual MSI database. I have been unable to get a call to InstallerPtr->OpenDatabase() to work. I've searched the web for info (MSDN is not helpful on this, it simply tells me the parameters, and then gives me a VBS example). Here is what I'm doing in a nutshell, can you spot anything wrong (I'm leaving out error checking to keep this brief):

InstallerPtr pInstaller;
pInstaller.CreateInstance( "WindowsInstaller.Installer" );
InstallerPtr->GetVersion() // this works
_variant_t dbMode;
dbMode.intVal = 1; // msiOpenDatabaseModeTransact
DatabasePtr dbOject = pInstaller->OpenDatabase( "myapplication.msi", dbMode );

OpenDatabase throws a COM error every time, and I can't seem to get a meaningful error message from it. Also, any attempt to call LastErrorRecord (which according to MSDN can be called if OpenDatabase() fails) results in an exception.

Long day. Frustrated. Probably missing something obvious. If you can push me in the right direction I would be most grateful.



  • Members
  • 6 posts

Posted 20 April 2006 - 19:01

FYI - Got past this. Seems even though I had closed Orca (which i had used to open my MSI file to check something before running my app); seems somehow Orca hung around, and still had some kind of "open" lock on my MSI. After I reboot my PC, then everything was golden!


  • Full Members
  • 26 posts

Posted 20 May 2006 - 21:05

Just for fun, here is an example using the installer API instead of the automation interface.


Christopher Painter, MCSE
Author of:
MSI Factory Provider for ADO.NET 2.0 (Work In Progress)
99 Bottles Of Beer - Windows Installer

PM for personal communication only. Please ask questions in the forums.