2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
19 #include "afsd_init.h"
27 char main_statusText[100];
31 extern int traceOnPanic;
33 extern void afsd_DbgBreakAllocInit();
34 extern void afsd_DbgBreakAdd(DWORD requestNumber);
37 * Notifier function for use by osi_panic
39 void afsd_notifier(char *msgp, char *filep, long line)
43 sprintf(tbuffer, "Error at file %s, line %d", filep, line);
45 strcpy(tbuffer, "Error at unknown location");
48 msgp = "Assertion failure";
50 MessageBox(NULL, tbuffer, msgp, MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
52 afsd_ForceTrace(TRUE);
61 /* Init function called when window application starts. Inits instance and
62 * application together, since in Win32 they're essentially the same.
64 * Function then goes into a loop handling user interface messages. Most are
65 * used to handle redrawing the icon.
69 HINSTANCE hPrevInstance,
75 afsd_SetUnhandledExceptionFilter();
78 afsd_DbgBreakAllocInit();
79 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF /* | _CRTDBG_CHECK_ALWAYS_DF */ | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF );
82 char *allocRequest = strtok(lpCmdLine, " \t");
85 afsd_DbgBreakAdd(atoi(allocRequest));
86 allocRequest = strtok(NULL, " \t");
91 if (!InitClass(hInstance))
94 if (!InitInstance(hInstance, nCmdShow))
97 while (GetMessage(&msg, NULL, 0, 0)) {
98 TranslateMessage(&msg);
99 DispatchMessage(&msg);
105 /* create the window type for our main window */
106 BOOL InitClass(HANDLE hInstance)
110 wc.style = CS_DBLCLKS; /* double-click messages */
111 wc.lpfnWndProc = (WNDPROC) MainWndProc;
114 wc.hInstance = hInstance;
115 wc.hIcon = LoadIcon(hInstance, "AFSDIcon");
116 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
117 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
118 wc.lpszMenuName = "AFSDMenu";
119 wc.lpszClassName = "AFSDWinClass";
121 return (RegisterClass(&wc));
124 /* initialize the process. Reads the init files to get the appropriate
132 TEXTMETRIC textmetric;
137 /* remember this, since it is a useful thing for some of the Windows
139 main_inst = hInstance;
141 /* create our window */
145 WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
159 /* lookup text dimensions */
161 GetTextMetrics(hDC, &textmetric);
162 nLineHeight = textmetric.tmExternalLeading + textmetric.tmHeight;
164 main_rect.left = GetDeviceCaps(hDC, LOGPIXELSX) / 4; /* 1/4 inch */
165 main_rect.right = GetDeviceCaps(hDC, HORZRES);
166 main_rect.top = GetDeviceCaps(hDC, LOGPIXELSY) / 4; /* 1/4 inch */
167 ReleaseDC(hWnd, hDC);
168 main_rect.bottom = main_rect.top + nLineHeight;
170 osi_InitPanic(afsd_notifier);
174 code = afsd_InitCM(&reason);
176 osi_panic(reason, __FILE__, __LINE__);
178 code = afsd_InitDaemons(&reason);
180 osi_panic(reason, __FILE__, __LINE__);
182 code = afsd_InitSMB(&reason, MessageBox);
184 osi_panic(reason, __FILE__, __LINE__);
186 ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
191 /* called with no locks with translated messages */
192 LONG APIENTRY MainWndProc(
194 unsigned int message,
198 HDC hDC; /* display-context variable */
199 PAINTSTRUCT ps; /* paint structure */
205 /* block attempts to open the window */
209 /* LOWORD(wParam) is command */
210 return (DefWindowProc(hWnd, message, wParam, lParam));
216 hDC = BeginPaint (hWnd, &ps);
217 /* nothing to print, but this clears invalidated rectangle flag */
222 RpcMgmtStopServerListening(NULL);
227 return (DefWindowProc(hWnd, message, wParam, lParam));