-//\r
-// DEBUG.CPP: Debugging support\r
-// by James L. Hammons\r
-// (C) 2002 Underground Software\r
-//\r
-// JLH = James Hammons <jlhamm@acm.org>\r
-//\r
-// Who When What\r
-// --- ---------- ------------------------------------------------------------\r
-// JLH 07/31/2002 Created this file\r
-// JLH 07/31/2002 Added debug log functions & system error logging functions\r
-// JLH 08/16/2002 Added debug log function for SQL error reporting, made\r
-// WriteLogMsg thread safe\r
-// JLH 12/10/2002 Added code to have a background message window\r
-// JLH 05/14/2004 Converted code to C++ (sans ODBC logging)\r
-// JLH 05/15/2005 Converted code to generic C++\r
-//\r
-\r
-//#include <windows.h>\r
-//#include <odbc.h>\r
-#include <stdarg.h>\r
-#include <stdio.h>\r
-#include "debug.h"\r
-\r
-// EQUATES\r
-\r
-//#define USDB_WRITEMESSAGE WM_USER + 1 // Display a message on the debug window\r
-\r
-// Function prototypes\r
-\r
-//void CreateDebugWin(void);\r
-//LRESULT CALLBACK DebugWinProc(HWND, UINT, WPARAM, LPARAM);\r
-\r
-// CONSTANTS\r
-\r
-const char logFilename[] = "debug.log";\r
-\r
-// DATA\r
-\r
-FILE * logFile = NULL;\r
-\r
-// UNINITIALIZED DATA\r
-\r
-//CRITICAL_SECTION csLock; // Critical section lock\r
-\r
-//\r
-// Open the debugging log file\r
-//\r
-void OpenDebugLog(void)\r
-{\r
-// hLogFile = CreateFile(logFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,\r
-// NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL, NULL);\r
-// InitializeCriticalSection(&csLock);\r
- logFile = fopen(logFilename, "wb");\r
-#ifdef DEBUGWIN\r
- CreateDebugWin();\r
-#endif\r
-}\r
-\r
-//\r
-// Close the debugging log file\r
-//\r
-void CloseDebugLog(void)\r
-{\r
-// CloseHandle(hLogFile);\r
- fclose(logFile);\r
-// DeleteCriticalSection(&csLock);\r
-\r
-// if (hDebugWnd)\r
-// DestroyWindow(hDebugWnd);\r
-}\r
-\r
-//\r
-// Write a message to the log file\r
-//\r
-/*void WriteLogMsg(char * msg)\r
-{\r
- if (!msg) // Check for valid pointer\r
- return;\r
-\r
- EnterCriticalSection(&csLock);\r
-\r
- if (hLogFile)\r
- WriteFile(hLogFile, msg, lstrlen(msg), &wfBytesWritten, NULL);\r
-\r
- if (hDebugWnd)\r
- SendMessage(hDebugWnd, USDB_WRITEMESSAGE, FALSE, (LPARAM)msg);\r
-\r
- LeaveCriticalSection(&csLock);\r
-}//*/\r
-\r
-//\r
-// This logger is used mainly to ensure that text gets written to the log file\r
-// even if the program crashes. The performance hit is acceptable in this case!\r
-//\r
-void WriteLogMsg(const char * msg, ...)\r
-{\r
- if (!msg) // Check for valid pointer\r
- return;\r
-\r
-// EnterCriticalSection(&csLock);\r
-\r
- va_list arg;\r
-\r
- va_start(arg, msg);\r
-// wvsprintf(str, msg, arg);\r
- if (logFile)\r
- {\r
- vfprintf(logFile, msg, arg);\r
- fflush(logFile);\r
- }\r
-\r
- va_end(arg);\r
-\r
-// if (hLogFile)\r
-// WriteFile(hLogFile, str, lstrlen(msg), &wfBytesWritten, NULL);\r
-\r
-// if (hDebugWnd)\r
-// SendMessage(hDebugWnd, USDB_WRITEMESSAGE, FALSE, (LPARAM)str);\r
-\r
-// LeaveCriticalSection(&csLock);\r
-}\r
-\r
-\r
-//\r
-// Display a system error message on the screen\r
-//\r
-/*void DisplaySysError(HWND hWnd)\r
-{\r
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL,\r
- GetLastError(), 1024, pBuf, 0, NULL);\r
- MessageBox(hWnd, pBuf, errTitle, MB_ICONERROR);\r
- LocalFree(pBuf);\r
-}\r
-\r
-//\r
-// Create "live log" debug window\r
-//\r
-void CreateDebugWin(void)\r
-{\r
- WNDCLASS wc;\r
-\r
- RtlZeroMemory(&wc, sizeof(wc));\r
- wc.lpfnWndProc = DebugWinProc;\r
- wc.hInstance = GetModuleHandle(NULL);\r
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);\r
- wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);\r
- wc.lpszClassName = CNDebug;\r
-\r
- if (!RegisterClass(&wc))\r
- return;\r
-\r
- hDebugWnd = CreateWindowEx(NULL, CNDebug, debugWin,\r
- WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_SYSMENU,\r
- 0, 0, 400, 400, NULL, NULL, NULL, NULL);\r
-}\r
-\r
-//\r
-// Debug "live log" window procedure\r
-//\r
-LRESULT CALLBACK DebugWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)\r
-{\r
- switch (uMsg)\r
- {\r
- // *****************\r
- // *** WM_CREATE ***\r
- // *****************\r
-\r
- case WM_CREATE:\r
- hEdit1 = CreateWindowEx(NULL, CNEdit, NULL,\r
- WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL,\r
- 0, 0, 1, 1, hWnd, NULL, NULL, NULL);\r
- break;\r
-\r
- // ******************\r
- // *** WM_DESTROY ***\r
- // ******************\r
-\r
- case WM_DESTROY:\r
- hDebugWnd = NULL; // Just in case user closes it himself...\r
- break;\r
-\r
- // ***************\r
- // *** WM_SIZE ***\r
- // ***************\r
-\r
- case WM_SIZE:\r
- SetWindowPos(hEdit1, NULL, 0, 0, lParam & 0xFFFF, lParam >> 16, SWP_NOMOVE | SWP_NOZORDER);\r
- break;\r
-\r
- // *************************\r
- // *** USDB_WRITEMESSAGE ***\r
- // *************************\r
-\r
- case USDB_WRITEMESSAGE:\r
- SendMessage(hEdit1, EM_SETSEL, -2, -2);\r
- SendMessage(hEdit1, EM_REPLACESEL, wParam, lParam);\r
- break;\r
-\r
- default:\r
- return DefWindowProc(hWnd, uMsg, wParam, lParam);\r
- }\r
-\r
- return 0;\r
-}\r
-//*/\r
+//
+// DEBUG.CPP: Debugging support
+// by James L. Hammons
+// (C) 2002 Underground Software
+//
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// Who When What
+// --- ---------- -----------------------------------------------------------
+// JLH 07/31/2002 Created this file
+// JLH 07/31/2002 Added debug log functions & system error logging functions
+// JLH 08/16/2002 Added debug log function for SQL error reporting, made
+// WriteLogMsg thread safe
+// JLH 12/10/2002 Added code to have a background message window
+// JLH 05/14/2004 Converted code to C++ (sans ODBC logging)
+// JLH 05/15/2005 Converted code to generic C++
+//
+
+//#include <windows.h>
+//#include <odbc.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include "debug.h"
+
+// EQUATES
+
+//#define USDB_WRITEMESSAGE WM_USER + 1 // Display a message on the debug window
+
+// Function prototypes
+
+//void CreateDebugWin(void);
+//LRESULT CALLBACK DebugWinProc(HWND, UINT, WPARAM, LPARAM);
+
+// CONSTANTS
+
+const char logFilename[] = "debug.log";
+
+// DATA
+
+FILE * logFile = NULL;
+
+// UNINITIALIZED DATA
+
+//CRITICAL_SECTION csLock; // Critical section lock
+
+//
+// Open the debugging log file
+//
+void OpenDebugLog(void)
+{
+// hLogFile = CreateFile(logFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
+// NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL, NULL);
+// InitializeCriticalSection(&csLock);
+ logFile = fopen(logFilename, "wb");
+#ifdef DEBUGWIN
+ CreateDebugWin();
+#endif
+}
+
+//
+// Close the debugging log file
+//
+void CloseDebugLog(void)
+{
+// CloseHandle(hLogFile);
+ fclose(logFile);
+// DeleteCriticalSection(&csLock);
+
+// if (hDebugWnd)
+// DestroyWindow(hDebugWnd);
+}
+
+//
+// Write a message to the log file
+//
+/*void WriteLogMsg(char * msg)
+{
+ if (!msg) // Check for valid pointer
+ return;
+
+ EnterCriticalSection(&csLock);
+
+ if (hLogFile)
+ WriteFile(hLogFile, msg, lstrlen(msg), &wfBytesWritten, NULL);
+
+ if (hDebugWnd)
+ SendMessage(hDebugWnd, USDB_WRITEMESSAGE, FALSE, (LPARAM)msg);
+
+ LeaveCriticalSection(&csLock);
+}//*/
+
+//
+// This logger is used mainly to ensure that text gets written to the log file
+// even if the program crashes. The performance hit is acceptable in this case!
+//
+void WriteLogMsg(const char * msg, ...)
+{
+ if (!msg) // Check for valid pointer
+ return;
+
+// EnterCriticalSection(&csLock);
+
+ va_list arg;
+
+ va_start(arg, msg);
+// wvsprintf(str, msg, arg);
+ if (logFile)
+ {
+ vfprintf(logFile, msg, arg);
+ fflush(logFile);
+ }
+
+ va_end(arg);
+
+// if (hLogFile)
+// WriteFile(hLogFile, str, lstrlen(msg), &wfBytesWritten, NULL);
+
+// if (hDebugWnd)
+// SendMessage(hDebugWnd, USDB_WRITEMESSAGE, FALSE, (LPARAM)str);
+
+// LeaveCriticalSection(&csLock);
+}
+
+
+//
+// Display a system error message on the screen
+//
+/*void DisplaySysError(HWND hWnd)
+{
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL,
+ GetLastError(), 1024, pBuf, 0, NULL);
+ MessageBox(hWnd, pBuf, errTitle, MB_ICONERROR);
+ LocalFree(pBuf);
+}
+
+//
+// Create "live log" debug window
+//
+void CreateDebugWin(void)
+{
+ WNDCLASS wc;
+
+ RtlZeroMemory(&wc, sizeof(wc));
+ wc.lpfnWndProc = DebugWinProc;
+ wc.hInstance = GetModuleHandle(NULL);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
+ wc.lpszClassName = CNDebug;
+
+ if (!RegisterClass(&wc))
+ return;
+
+ hDebugWnd = CreateWindowEx(NULL, CNDebug, debugWin,
+ WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_SYSMENU,
+ 0, 0, 400, 400, NULL, NULL, NULL, NULL);
+}
+
+//
+// Debug "live log" window procedure
+//
+LRESULT CALLBACK DebugWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ // *****************
+ // *** WM_CREATE ***
+ // *****************
+
+ case WM_CREATE:
+ hEdit1 = CreateWindowEx(NULL, CNEdit, NULL,
+ WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL,
+ 0, 0, 1, 1, hWnd, NULL, NULL, NULL);
+ break;
+
+ // ******************
+ // *** WM_DESTROY ***
+ // ******************
+
+ case WM_DESTROY:
+ hDebugWnd = NULL; // Just in case user closes it himself...
+ break;
+
+ // ***************
+ // *** WM_SIZE ***
+ // ***************
+
+ case WM_SIZE:
+ SetWindowPos(hEdit1, NULL, 0, 0, lParam & 0xFFFF, lParam >> 16, SWP_NOMOVE | SWP_NOZORDER);
+ break;
+
+ // *************************
+ // *** USDB_WRITEMESSAGE ***
+ // *************************
+
+ case USDB_WRITEMESSAGE:
+ SendMessage(hEdit1, EM_SETSEL, -2, -2);
+ SendMessage(hEdit1, EM_REPLACESEL, wParam, lParam);
+ break;
+
+ default:
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);
+ }
+
+ return 0;
+}
+//*/