add-missing-include-file-afsd-windows-20031203
[openafs.git] / src / WINNT / afsd / afsd.c
index a481f2e..8e29f67 100644 (file)
@@ -21,6 +21,9 @@
 #include <stdlib.h>
 #include <winsock2.h>
 
+#ifdef _DEBUG
+#include <crtdbg.h>
+#endif
 
 HANDLE main_inst;
 HWND main_wnd;
@@ -30,6 +33,9 @@ osi_log_t *afsd_logp;
 
 extern int traceOnPanic;
 
+extern void afsd_DbgBreakAllocInit();
+extern void afsd_DbgBreakAdd(DWORD requestNumber);
+
 /*
  * Notifier function for use by osi_panic
  */
@@ -69,7 +75,23 @@ int WINAPI WinMain(
 {
        MSG msg;
        
-       if (!InitClass(hInstance))
+    afsd_SetUnhandledExceptionFilter();
+       
+#ifdef _DEBUG
+    afsd_DbgBreakAllocInit();
+    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF /* | _CRTDBG_CHECK_ALWAYS_DF */ | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF );
+    if (lpCmdLine)
+    {
+        char *allocRequest = strtok(lpCmdLine, " \t");
+        while (allocRequest)
+        {
+            afsd_DbgBreakAdd(atoi(allocRequest));
+            allocRequest = strtok(NULL, " \t");
+        }
+    }
+#endif 
+
+    if (!InitClass(hInstance))
                return (FALSE);
 
        if (!InitInstance(hInstance, nCmdShow))
@@ -111,9 +133,8 @@ BOOL InitInstance(
        HWND hWnd;
        HDC hDC;
        TEXTMETRIC textmetric;
-       RECT rect;
        INT nLineHeight;
-        long code;
+    long code;
        char *reason;
  
        /* remember this, since it is a useful thing for some of the Windows
@@ -138,7 +159,6 @@ BOOL InitInstance(
        if (!hWnd)
                return (FALSE);
 
-
        /* lookup text dimensions */
        hDC = GetDC(hWnd);
        GetTextMetrics(hDC, &textmetric);
@@ -148,7 +168,7 @@ BOOL InitInstance(
        main_rect.right  = GetDeviceCaps(hDC, HORZRES);
        main_rect.top    = GetDeviceCaps(hDC, LOGPIXELSY) / 4;   /* 1/4 inch */
        ReleaseDC(hWnd, hDC);
-       main_rect.bottom = rect.top + nLineHeight;
+       main_rect.bottom = main_rect.top + nLineHeight;
 
        osi_InitPanic(afsd_notifier);