MSIOpenDatabase and MSISummaryInfoSetProperty

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I'm trying to write a single feature to an MSI DB using C# there is so little documentation that I have had to piece together everything by hand. Any help would be appreciated

I tried in C# to set up the MSIOpenDatabase to open an existing MSI DB. I get a handle of 1. I'm not sure what I'm doing wrong. The RC is 0, so it thinks it's successful. Help

Looking through the various SDK msi*.h files, I found that the value for the MSIDBOPEN_TRANSACT is actually 1, so that's what I put in. I've tried to look for another way to do it, and can't seem to find it. And I think that may be my problem, but I can't find a decent answer

Thanks
Pau

public const int MSIDBOPEN_TRANSACT = 1

tr
{
msiName = txtManufacturer.Text + "_" + txtPackageName.Text + "_" + txtVersion.Text + "_" + txtOS.Text
msiFileName= msiName+".msi"
//System.IO.File.Copy("template.msi",msiFileName,true)
//Load template.ms
IntPtr dbHandle = IntPtr.Zero
rc = CallMsi.MsiOpenDatabase(msiFileName,MSIDBOPEN_TRANSACT, ref dbHandle)
//CallMsi to MsiSummaryInfoSetProperty to input each of the summary info properties
rc = CallMsi.MsiSummaryInfoSetProperty(dbHandle,PID_TITLE, VT_LPSTR,0,ref file_time,msiName)
rc = CallMsi.MsiSummaryInfoPersist(dbHandle)
//Check to see if MsiSetProperty is needed
//Save file by correct name
rc = CallMsi.MsiDatabaseCommit(dbHandle)
rc = CallMsi.MsiCloseHandle(dbHandle)
}
catch ( Exception d
{
Console.WriteLine ( d ) ;
}
 
Paul,

Which of the functions is failing? Can you post your DllImport
declarations?



Mattias
 
Because when it gets to the next call for the handle, I get back a return code of 6, which is an Invalid Handle. Because when I try to update the Summary Info, it appears to work, but never actually makes any changes to the file.

Paul
 
Paul,
Because when it gets to the next call for the handle, I get back a return code of 6, which is an Invalid Handle.

Ah, now I understand. MsiSummaryInfoSetProperty expects a summary
information handle, but you're passing it the database handle. You
should call MsiGetSummaryInformation to retrieve the correct handle
for MsiSummaryInfoSetProperty.



Mattias
 
I tried that. Unfortunately, the summary handle gives me a 2. I think it's got to be something in the way I'm declaring the msihandle. I'm doing ref IntPtr. I'm wondering if it may be something else

Paul
 
Paul,
I tried that. Unfortunately, the summary handle gives me a 2.

And that's no good?

Again, I don't see why you care about the value of the handle. A
handle is supposed to be an opaque thing, and you shouldn't have to
care about what the value is, as long as it's not the special "invalid
handle" value (zero for MSI handles).

MsiGetSummaryInformation indicates success by returning zero as the
return value, and a nonzero error code for failure. That should be
enough to determine whether the function succeeds or not, don't look
at the handle value.



Mattias
 
Back
Top