PDA

View Full Version : How to write to the installer log from a deferred CA



willwright
06-15-2004, 10:37 PM
I have a deferred custom action DLL (C++) that makes calls to Win32 functions. If one of those calls fails I would like to write that information to the installer log. However, it appears that I cannot write to the log from a deferred CA due to not the deferred CA not having suffient context.

Does anyone know if this should be possible or if there is another way to do it.

Any advice would be greatly appreciated.

Thanks,
Will

Below is the code that I use to write to the installer log:

int WriteLogMessage(MSIHANDLE hInstall, TCHAR *pszMessage, INSTALLMESSAGE eMessageType)
{
PMSIHANDLE hRec = NULL;
TCHAR szFormattedOutput[MAX_LOG_MESSAGE_LENGTH];
DWORD strLen;

// Get the length of the message (including terminating NULL)
strLen = (DWORD) _tcslen(pszMessage) + 1;
if (strLen > MAX_LOG_MESSAGE_LENGTH) {
return -1;
}

hRec = MsiCreateRecord(1);
if (NULL == hRec) {
return -1;
}


//Copy the string to the MSI record
if (MsiRecordSetString(hRec, 1, pszMessage) != ERROR_SUCCESS) {
return -1;
}

//Set the format string of the MSI record to NULL
if (MsiRecordSetString(hRec, 0, TEXT("[1]")) != ERROR_SUCCESS) {
return -1;
}

//Format the record to get rid of the '1.'
if (MsiFormatRecord(hInstall, hRec, szFormattedOutput, &strLen) != ERROR_SUCCESS) {
return -1;
}

//Write the message to the log
if (MsiProcessMessage(hInstall, eMessageType, hRec) != IDOK) {
return -1;
}

return 0;
}

willwright
06-16-2004, 03:22 PM
I got a reply from somone in the microsoft.publi.cplatformsdk.msi newsgroup which solved the problem.

When I simplifed my code to the following, it worked fine.

int WriteLogMessage(MSIHANDLE hInstall, LPCTSTR pszMessage)
{
PMSIHANDLE hRec = NULL;

hRec = MsiCreateRecord(1);
if (NULL == hRec) {
return -1;
}

//Copy the string to the MSI record
if (MsiRecordSetString(hRec, 0, pszMessage) != ERROR_SUCCESS) {
return -1;
}

//Write the message to the log
if (MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_INFO), hRec) != IDOK) {
return -1;
}

return 0;
}

Will