Microsoft Logparser and Windows 2000 Server issue

Microsoft Logparser allows you to analyze log files in a generic SQL way. You can analyze your own log files, and even binary log files. For the latter, you need to provide a com object implementing an interface so that the Logparser can read your binary log file.

However, it looks like there is a compatibility issue with Windows 2000 (I’m running the service pack 4). When declaring TIMESTAMP fields or integer fileds, and initializing the variant object in the GetValue method with the V_I8 or V_DATE values, Logparser gives a « Error retrieving field: Bad variable type ».

Using the same version of Logparser (2.2.10) and the same COM DLL on a XP or a 2003 Server machine, everything works fine…

Any clue for a solution ?

HEAP[test.exe]: Invalid Address specified to RtlValidateHeap

Different problems can cause this error.

It is often related to the settings of your projects. If you use different run-time libraries for your main program and for your libraries/DLLs, they will not allocate and deallocate memory in the same way. Consequently, if some memory allocated by a library is released by another one, you may get this kind of error.
You can check your projects settings in : project->settings->C++->Code generation->Use run-time library.

However, the explanation can be really simpler. Just try to delete two times a same object, and you may get this error. To ensure that an object is not deleted twice, just put a breakpoint in its destructor.
I encountered this problem after doing a stupid mistake. I declared a CWinThread m_thread member variable in a class CMyClass I forgot that its m_bAutoDelete member variable is set to TRUE by default. Logically, m_thread was deleting itself once it was terminated. And of course, the destructor of CMyClass was trying to delete m_thread too… BOOM !!!

How to convert a UNICODE string to an ANSI C null-terminated string ?

In some cases, you may need to convert a unicode string into an ANSI C null-terminated string. The WideCharToMultiByte function allows you to do this.

In the following example, I have used the ReadDirectoryChangesW function to detect a file modification in a directory. The name of the modified file is stored in UNICODE format. I want to convert it to  a standard C string.

PFILE_NOTIFY_INFORMATION pstFileNotif;

// Initialization of pstFileNotif

char szNotifFilename[ MAX_PATH ] = { 0 };
int iNbChar = WideCharToMultiByte(
CP_OEMCP,
NULL,
pstFileNotif->FileName,
pstFileNotif->FileNameLength / sizeof( WCHAR ),
szNotifFilename,
sizeof( szNotifFilename ) / sizeof( char ),
NULL, NULL ) ;

if ( iNbCar == 0 )
{
// Error
}

Be careful : the size of the 2 strings is not their length in bytes, but their length in characters (a UNICODE character takes 2 bytes)