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.
Photo

API calls to MSI file from VB.NET


1 reply to this topic

JFaulkner

JFaulkner
  • Members
  • 1 posts

Posted 13 May 2002 - 11:48

Hi

I am trying to use API calls from a visual basic program to retrieve information from the MSI databse, without much sucsess. The code is as follows:

Function GetMSISize(ByVal strPath As String) As Integer
   Dim intViewHandle As Integer
   Dim intDBHandle As Integer
   Dim intRecHandle As Integer
   Dim intRC As Integer
   Dim strSQL As String
   Dim intSize As Integer
   
   strSQL = "SELECT FileSize FROM File"

   intRC = MsiOpenDatabase(strPath, CStr(MSIDBOPEN_READONLY), intDBHandle)
   intRC = MsiDatabaseOpenView(intDBHandle, strSQL, intViewHandle)
   intRC = MsiViewExecute(intViewHandle, 0)
   intRC = MsiViewFetch(intViewHandle, intRecHandle)
   Do While MsiViewFetch(intViewHandle, intRecHandle) = ERROR_SUCCESS
      intSize = intSize + MsiRecordGetInteger(intRecHandle, 1)
      intRC = MsiCloseHandle(intRecHandle)
   Loop
   intRC = MsiCloseHandle(intViewHandle)
   intRC = MsiCloseHandle(intDBHandle)

   GetMSISize = intSize / 1048576

End Function

It seems to run fine until the MSIViewExecute function which returns ERROR_INVALID_HANDLE. I'm sertain that I have declared all the API functions and constants correctly. Does anyone have any ideas?

Julia

pdriley

pdriley
  • Members
  • 91 posts

Posted 13 May 2002 - 12:50

Haven't actually tried to do anything like this... yet... but I have a thought.

Could you use the Windows Installer automation objects?

Project->Add a Reference, COM Tab, check Microsoft Windows Installer Object Library.  Then you should be able to create an Installer object and a Database from that, etc.

The API actually seems to be developed FROM the COM object for use in C++; in anything else the COM object is usually much easier.
Paul Riley (Vector Networks), InstallShield User.