I’m relatively new to Visual C++. I’m trying to build a module to consume log events generated by the IIS 7.0 server in order to be able to analyze these logs in real-time. I found a Microsoft article which provides code that accomplishes the real-time capture:
http://learn.iis.net/page.aspx/581/advanced-logging-for-iis-70—real-time-logging#module
After some work, I’ve gotten this code to compile into a DLL on my machine (64-bit Windows XP with Visual Studio .NET 2008). I’m curious about the double initiation (?) of the m_hEventLog ‘event viewer’. I’ve reproduced the constructor and the line in the private section which both seem to create a handle to the event viewer.
The constructor:
MyGlobalModule()
{
m_hEventLog = RegisterEventSource( NULL, L"IISADMIN" );
}
private:
HANDLE m_hEventLog;
My question: Why does m_hEventLog need to be declared twice?
Thanks in advance,
-Eric
This line:
is declaration of the variable
m_hEventLog. It means that when an object of typeMyGlobalModulewill be declared, that will contain a member namedm_hEventLog. When the object is declared, or in other words, constructed, the constructor is called. It executes the following line:The this line will execute,
RegisterEventSource()will be called and its return value will be assigned tom_hEventLog.EDIT
Consider the following program:
When this program is executed, nothing actually happens for
class Abecause there is no variabledeclareddefined of type A. If themain()function is written in this way:then an object of type
Aisdeclareddefined (provided that compiler didn’t optimize anything). It hold an integer inside it (the member variablea).A‘s constructor will be called so thatAis initialized. And the constructor will initializeA‘sato 0. Note I used initializer list to initializeA::a.