#include "stdafx.h"
void
Log(MSIHANDLE hModule,
LPCTSTR
sString)
{
PMSIHANDLE hRecord = ::MsiCreateRecord(2);
if
(hRecord == NULL)
return
;
UINT
uiAnswer = ::MsiRecordSetString(hRecord, 0, sString);
if
(uiAnswer != ERROR_SUCCESS)
return
;
::MsiProcessMessage(hModule, INSTALLMESSAGE(INSTALLMESSAGE_INFO), hRecord);
}
void
SimpleLogString1(MSIHANDLE hModule,
LPCTSTR
s)
{
static
TCHAR
str[513];
_tcscpy_s(str, 512, s ? s : _T(
"<null>"
));
Log(hModule, str);
}
void
SimpleLogString2(MSIHANDLE hModule,
LPCTSTR
s,
LPCTSTR
t)
{
static
TCHAR
str[513];
_tcscpy_s(str, 512, s ? s : _T(
"<null>"
));
_tcscat_s(str, 512, t ? t : _T(
"<null>"
));
Log(hModule, str);
}
void
SimpleLogString3(MSIHANDLE hModule,
LPCTSTR
s,
LPCTSTR
t,
LPCTSTR
u)
{
static
TCHAR
str[513];
_tcscpy_s(str, 512, s ? s : _T(
"<null>"
));
_tcscat_s(str, 512, t ? t : _T(
"<null>"
));
_tcscat_s(str, 512, u ? u : _T(
"<null>"
));
Log(hModule, str);
}
void
SimpleLogString4(MSIHANDLE hModule,
LPCTSTR
s,
LPCTSTR
t,
LPCTSTR
u,
LPCTSTR
v)
{
static
TCHAR
str[513];
_tcscpy_s(str, 512, s ? s : _T(
"<null>"
));
_tcscat_s(str, 512, t ? t : _T(
"<null>"
));
_tcscat_s(str, 512, u ? u : _T(
"<null>"
));
_tcscat_s(str, 512, v ? v : _T(
"<null>"
));
Log(hModule, str);
}
UINT
RETURN_ON_ERROR(
UINT
retval, MSIHANDLE hModule,
LPCTSTR
s)
{
if
(ERROR_SUCCESS != retval) {
SimpleLogString1(hModule, s);
return
1;
}
return
0;
}
void
PrintUINT(MSIHANDLE hModule,
UINT
i)
{
static
TCHAR
sNumber[100];
_stprintf_s(sNumber, 99, _T(
"%d"
), i);
SimpleLogString2(hModule, _T(
"DEBUG: UINT="
), sNumber);
}
void
PrintLastErrorDetails(MSIHANDLE hModule)
{
PMSIHANDLE hLastErrorRec = MsiGetLastErrorRecord();
TCHAR
* szExtendedError = NULL;
DWORD
cchExtendedError = 0;
if
(hLastErrorRec) {
UINT
uiStatus = MsiFormatRecord(NULL, hLastErrorRec, TEXT(
""
), &cchExtendedError);
if
(ERROR_MORE_DATA == uiStatus) {
cchExtendedError++;
szExtendedError =
new
TCHAR
[cchExtendedError];
if
(szExtendedError) {
uiStatus = MsiFormatRecord(NULL, hLastErrorRec, szExtendedError, &cchExtendedError);
if
(ERROR_SUCCESS == uiStatus) {
SimpleLogString2(hModule, _T(
"DEBUG: ExtendedError="
), szExtendedError);
}
delete
[] szExtendedError;
szExtendedError = NULL;
}
}
}
}