The Following code is used to keep a log about my process' activity. The problem is that it the debug output file gets the wrong name (unreadable characters). I can't figure out where my pointers go wild. Sorry for such a silly problem .
Code:
#include "includes.h"
#include "externs.h"
HANDLE hDebug;
HANDLE mDebug;
void AddLog(char *buffer)
{
#ifdef DEBUG
DWORD dwBytesWritten=0;
DWORD dwBytesToWrite=0;
dwBytesToWrite =(DWORD) strlen(buffer);
if( hDebug == INVALID_HANDLE_VALUE || hDebug == NULL )
return;
WaitForSingleObject(mDebug, INFINITE);
while(dwBytesWritten < dwBytesToWrite)
{
WriteFile(hDebug, buffer+dwBytesWritten, dwBytesToWrite - dwBytesWritten, &dwBytesWritten,NULL);
}
ReleaseMutex(mDebug);
#endif
}
void StartDebug()
{
wchar_t FileDebug[]={'d','e','b','u','g','.','e','t','h'};
mDebug = CreateMutex(NULL, false, NULL);
hDebug = CreateFile( (LPWSTR) FileDebug,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
}