HANDLE m_hEventSource = ::RegisterEventSource(NULL, // local machine
("NT Service Demonstration")); // source name
在使用RegisterEventSource這個函數,第二個參數必須是
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application]
中sources中含有的。
下圖點擊放大。

自我感悟,每個消息的是從source中找他的消息ID的。所以應用程序改是沒有什么用的。
用自帶的.mc經消息編譯器編譯后,生成的那些都沒有用。
.mc文件經過編譯生成三個文件 .h, .rc, msg00001.bin文件。
void LogEvent(WORD wType, DWORD dwID,
const char* pszS1 = NULL,
const char* pszS2 = NULL,
const char* pszS3 = NULL);
int main( )
{
LogEvent(EVENTLOG_INFORMATION_TYPE, EVMSG_DEMO1, "WMIAdapter");
return 0;
}
void LogEvent(WORD wType, DWORD dwID,
const char* pszS1,
const char* pszS2,
const char* pszS3)
{
const char* ps[3];
ps[0] = pszS1;
ps[1] = pszS2;
ps[2] = pszS3;
int iStr = 0;
for (int i = 0; i < 3; i++) {
if (ps[i] != NULL) iStr++;
}
// Check the event source has been registered and if
// not then register it now
HANDLE m_hEventSource = ::RegisterEventSource(NULL, // local machine
("WMIAdapter")); // source name
bool bi;
if (m_hEventSource) {
bi = ::ReportEvent(m_hEventSource,
wType,
0,
dwID,
NULL, // sid
iStr,
0,
ps,
NULL);
}
}