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

Trying to log message in managed CA


1 reply to this topic

PThomas

PThomas
  • Full Members
  • 3 posts

Posted 21 February 2007 - 21:55

So I'm experimenting with managed CAs. I created a managed C++ dll that calls my C# assembly and that works fine. Using PInvoke, I have my C# assembly getting properties and displaying the value in a message box so I know my MSI handle is good. The next thing I want to try is to log a message but MsiProcessMessage keeps failing with "-1" and I don't know why. Can anyone spot a problem with this code?

The following is the code, then the PInvoke signatures, then the DgbView output.

BTW, the message I am trying to log is about 220 characters. My buffer sizes in this code are all over the place because I was playing with them a bit to see if they changed the results.

public void LogMessage(string message)
{
StringBuilder outBuff = new StringBuilder(1024);
int size = 254;
IntPtr hRecord = MsiApi.MsiCreateRecord(2);
Trace.WriteLine("Record handle is: " + hRecord.ToString());
int retValue = MsiApi.MsiRecordSetString(hRecord, 0, "[1]");
Trace.WriteLine("Return is: " + retValue.ToString());
retValue = MsiApi.MsiRecordSetString(hRecord, 1, message);
Trace.WriteLine("Return is: " + retValue.ToString());
retValue = MsiApi.MsiFormatRecord(_msiHandle,hRecord, outBuff, ref size);
Trace.WriteLine("Return is: " + retValue.ToString());
retValue = MsiApi.MsiProcessMessage(_msiHandle, MsiApi.InstallMessage.Info, hRecord);
Trace.WriteLine("Return is: " + retValue.ToString());
}

public class MsiApi
{
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern int MsiProcessMessage(IntPtr hInstall, InstallMessage eMessageType, IntPtr hRecord);

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr MsiCreateRecord(int numParams);

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern int MsiRecordSetString(IntPtr hRecord, int iField, string szValue);

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern int MsiGetProperty(IntPtr handle, string
szName, [Out] StringBuilder szValueBuf, ref int pchValueBuf);

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern int MsiFormatRecord(IntPtr hInstall, IntPtr hRecord, [Out] StringBuilder szValueBuf, ref int pchValueBuf);

public enum InstallMessage : long
{
FatalError = 0x00000000L,
Error = 0x10000000L,
Warning = 0x20000000L,
User = 0x30000000L,
Info = 0x04000000L,
FilesInUser = 0x05000000L,
ResolveSource = 0x06000000L,
OutOfDiskSpace = 0x07000000L,
ActionStart = 0x08000000L,
ActionData = 0x09000000L,
Progress = 0x0A000000L,
CommandData = 0x0B000000L,
Initialize = 0x0C000000L,
Terminiate = 0x0D000000L,
ShowDialog = 0x0E000000L
};
}


Output:

[2424] Record handle is: 14
[2424] Return is: 0
[2424] Return is: 0
[2424] Return is: 0
[2424] Return is: -1

Thanks for taking the time to look at this

Peter

PThomas

PThomas
  • Full Members
  • 3 posts

Posted 21 February 2007 - 22:30

I found A problem but not THE problem. I wasn't closing the record handle which was causing an error to be logged to the MSI log file after the CA completed. Now I'm closing the handle and I don't get that error logged but MsiProcessMessage still fails.

Ideas?