Changes between Initial Version and Version 1 of PlugIns/MFC/usagelog.dll


Ignore:
Timestamp:
10/02/12 12:01:39 (12 years ago)
Author:
sherbold
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PlugIns/MFC/usagelog.dll

    v1 v1  
     1= usagelog.dll = 
     2 
     3This tool is implemented as a Dynamic Linked Library (DLL) called '''{{{usagelog.dll}}}'''. The interface of the DLL is kept extremly simple, it provides only two functions: one to start the logging and one to end it. The logging itself is done, by utilizing the ''message hooks''. Hooks are placed inside the message processing chain of a program. Using them, it is possible to inspect the internal messaging of a program without modifying the program itself. For the different kinds of message, different hooks are provided. Currently, two hooks seem to be sufficient: a {{{WH_GETMESSAGE}}} and a {{{WH_CALLWNDPROC}}} hook.  
     4 
     5To be able to replay logged actions, three general informations are needed: 
     6 1. The correct order of the events. 
     7 1. A description of the event itself. 
     8 1. The target of the event. 
     9 
     10To identify the order of the event, the order of the logged messages is used. It is assumed that this logging order is correct and that therefore the events took also place in this order.  
     11 
     12To describe the events themselves is more difficult. The logger has the responsibility to log any information that might be needed for event identification or replaying of events. To this aim, the messages are filtered based on their ''type'', e.g., {{{WM_CREATE}}} and {{{WM_COMMAND}}}.  
     13 
     14The target of the event is identified using the HWND of the GUI object that the event has been addressed to.  
     15 
     16== Build information == 
     17 
     18The project is developed with Visual Studio 2008 and should compile cleanly. If the linker crashes during incremental builds, simply build again. It will be successful the second time. 
     19 
     20The logging protocol is selected using defines: 
     21 - {{{__USING_MTRACE__}}} can only be compiled in cooperation with software from [http://www.mahr.com Mahr] and should therefore not be enabled.  
     22 - {{{__USING_COSTUMLOG__}}} writes a logfile "usagelog.txt" to the execution path 
     23 - {{{__ENCODE_BASE64__}}} defines that the log shall be encoded base64 
     24 - {{{__TIMING__}}} includes timing information, i.e., measurements how long the logging itself requires, to measure if the application is slowed down due to the logging. 
     25 
     26== Architecture == 
     27 
     28The architecture of the logging mechanism is rather simple. It is a DLL written in C++. The interface provides currently only functions to start and stop the logging: 
     29{{{ 
     30#!cpp 
     31__declspec(dllexport) void __cdecl InitUsagelog(); 
     32__declspec(dllexport) void __cdecl ReleaseUsagelog(); 
     33}}} 
     34 
     35The message filter is defined in as a simple switch-statement and may only be modified at compile time.  
     36 
     37As data format for the logs a simple XML scheme is used, described by the following DTD: 
     38{{{ 
     39#!xml 
     40<!ELEMENT log (session*)> 
     41<!ELEMENT session (msg*)> 
     42<!ELEMENT msg (param*)> 
     43<!ELEMENT param EMPTY> 
     44<!ATTLIST msg 
     45  type  CDATA #REQUIRED> 
     46<!ATTLIST param 
     47  name  CDATA #REQUIRED 
     48  value CDATA #REQUIRED> 
     49}}} 
     50A ''log'' consists of several ''sessions'', i.e., program executions. Every session consists of the messages it recorded. A message consists of a ''type'' and of parameters. The of a message is describes by an integer that identifies the windows message that has been send, e.g., {{{WM_CREATE}}}, {{{WM_DESTROY}}} or {{{WM_LBUTTONCLICK}}}. The parameters are ''name'', ''value'' pairs, both stored as strings. Using the parameters, it is possible to store additional information to messages in a generic and flexible way. For example, in case a window is created additional information about the window, like its resource id. 
     51 
     52== How to use == 
     53 
     54To enable the logging the {{{usagelog.dll}}} has to be loaded: 
     55{{{ 
     56#!cpp 
     57HINSTANCE hinstDll = NULL; // Handle of the Dll. Should be global, as it needs to be used to start/stop the logging and to unload the Dll. 
     58 
     59// Load the Dll and check for errors 
     60hinstDll = LoadLibrary(L"usagelog.dll"); 
     61if( hinstDll==NULL ) { 
     62        MessageBox(0, L"Loading of DLL failed", L"Failure", MB_OK); 
     63} 
     64}}} 
     65 
     66Then, to start the logging {{{InitUsagelog()}}} needs to be called: 
     67{{{ 
     68#!cpp 
     69void (__cdecl *InitUsagelogPtr)(void) = NULL; // Function pointer with the signature of InitUsagelog 
     70 
     71// Obtain a function pointer to InitUsagelog() from the Dll and check for errors 
     72InitUsagelogPtr = (void (*)(void)) GetProcAddress(hinstDll, "InitUsagelog"); 
     73if( InitUsagelogPtr==NULL ) { 
     74        MessageBox(0, L"Loading of InitFuncPtr failed", L"Failure", MB_OK); 
     75} 
     76// Start the logging 
     77if( InitUsagelogPtr!=NULL ) { 
     78        InitUsagelogPtr(); 
     79} 
     80}}} 
     81 
     82To stop the logging, {{{ReleaseUsagelog()}}} needs to be called: 
     83{{{ 
     84#!cpp 
     85void (*ReleaseUsagelogPtr)(void) = NULL; // Function pointer with the signature of ReleaseUsagelog() 
     86 
     87// Obtain a function pointer to InitUsagelog() from the Dll and check for errors 
     88ReleaseUsagelogPtr = (void (*)(void)) GetProcAddress(hinstDll, "ReleaseUsagelog"); 
     89if( ReleaseUsagelogPtr==NULL ) { 
     90        MessageBox(0, L"Loading of ReleaseFuncPtr failed", L"Failure", MB_OK); 
     91} 
     92}}} 
     93 
     94Finally, if no more logging is required, the Dll may be unloaded: 
     95{{{ 
     96#!cpp 
     97FreeLibrary(hinstDll); 
     98}}} 
     99 
     100== Additional Features == 
     101 * Unicode logging 
     102  * encoding depends on the compiler, UTF-16LE with Visual Studio 2008 
     103 * Base64 encoding of log to support writing ASCII while using Unicode internally