I have a setup project in Visual Studio 2008 with Custom Action class. I have to execute the msi on command line using msiexec /i SetupProject.ms i /qb /l* out.txt command. The task is to write custom messages to the log file. This can be done by MsiProcessMessa ge function from Windows Installer API. To achieve this I have downloaded the C# wrapper class posted on CodeProject.com (http://www.codeproject.com/csharp/msiinterop.asp) that provides a C# interface to the common Windows Installer APIs.
Now the problem is, I am not able to get the MSIHANDLE for the current instance of the installer in custom action class using that wrapper class. My function Write to log goes like this,
private void WriteToLogFile( string sMessage)
{
IntPtr hInstall = IntPtr.Zero;
IntPtr hRec;
uint lCount;
MsiInterop.MsiO penPackage(@" D:\SetupProject .msi", out hInstall);
//Validate the passed-in string
if (sMessage.Lengt h == 0)
{
return;
}
//Create a record with only one field
hRec = MsiInterop.MsiC reateRecord(1);
//Handle problem creating record
if ((int)hRec == 0)
{
return;
}
//Create the full message
//szFullMessage = STARS + szMessage;
//Set that one field to the passed-in string
MsiInterop.MsiR ecordSetString( hRec, 1, sMessage);
//Set the formatting string to NULL
MsiInterop.MsiR ecordSetString( hRec, 0, "[1]");
//Get length of message to pass to MsiFormatRecord
lCount = (uint)sMessage. Length;
//Format the record to get rid of the '1.'
MsiInterop.MsiF ormatRecord(hIn stall, hRec, sMessage, ref lCount);
//Handle processing the message
MsiInterop.MsiP rocessMessage(h Install, MsiInstallMessa ge.Info, hRec);
}
In the above function, it neither takes any handle to the installer nor writes any thing to the log file.
Thanks in advance,
Yogita
Now the problem is, I am not able to get the MSIHANDLE for the current instance of the installer in custom action class using that wrapper class. My function Write to log goes like this,
private void WriteToLogFile( string sMessage)
{
IntPtr hInstall = IntPtr.Zero;
IntPtr hRec;
uint lCount;
MsiInterop.MsiO penPackage(@" D:\SetupProject .msi", out hInstall);
//Validate the passed-in string
if (sMessage.Lengt h == 0)
{
return;
}
//Create a record with only one field
hRec = MsiInterop.MsiC reateRecord(1);
//Handle problem creating record
if ((int)hRec == 0)
{
return;
}
//Create the full message
//szFullMessage = STARS + szMessage;
//Set that one field to the passed-in string
MsiInterop.MsiR ecordSetString( hRec, 1, sMessage);
//Set the formatting string to NULL
MsiInterop.MsiR ecordSetString( hRec, 0, "[1]");
//Get length of message to pass to MsiFormatRecord
lCount = (uint)sMessage. Length;
//Format the record to get rid of the '1.'
MsiInterop.MsiF ormatRecord(hIn stall, hRec, sMessage, ref lCount);
//Handle processing the message
MsiInterop.MsiP rocessMessage(h Install, MsiInstallMessa ge.Info, hRec);
}
In the above function, it neither takes any handle to the installer nor writes any thing to the log file.
Thanks in advance,
Yogita
Comment