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"
30 char main_statusText[100];
34 extern int traceOnPanic;
36 extern void afsd_DbgBreakAllocInit();
37 extern void afsd_DbgBreakAdd(DWORD requestNumber);
40 * Notifier function for use by osi_panic
42 void afsd_notifier(char *msgp, char *filep, long line)
46 sprintf(tbuffer, "Error at file %s, line %d", filep, line);
48 strcpy(tbuffer, "Error at unknown location");
51 msgp = "Assertion failure";
53 MessageBox(NULL, tbuffer, msgp, MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
55 afsd_ForceTrace(TRUE);
65 /* Init function called when window application starts. Inits instance and
66 * application together, since in Win32 they're essentially the same.
68 * Function then goes into a loop handling user interface messages. Most are
69 * used to handle redrawing the icon.
73 HINSTANCE hPrevInstance,
79 afsd_SetUnhandledExceptionFilter();
82 afsd_DbgBreakAllocInit();
83 _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF /* | _CRTDBG_CHECK_ALWAYS_DF */ | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF );
86 char *allocRequest = strtok(lpCmdLine, " \t");
89 afsd_DbgBreakAdd(atoi(allocRequest));
90 allocRequest = strtok(NULL, " \t");
95 if (!InitClass(hInstance))
98 if (!InitInstance(hInstance, nCmdShow))
101 while (GetMessage(&msg, NULL, 0, 0)) {
102 TranslateMessage(&msg);
103 DispatchMessage(&msg);
109 /* create the window type for our main window */
110 BOOL InitClass(HANDLE hInstance)
114 wc.style = CS_DBLCLKS; /* double-click messages */
115 wc.lpfnWndProc = (WNDPROC) MainWndProc;
118 wc.hInstance = hInstance;
119 wc.hIcon = LoadIcon(hInstance, "AFSDIcon");
120 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
121 wc.hbrBackground = GetStockObject(WHITE_BRUSH);
122 wc.lpszMenuName = "AFSDMenu";
123 wc.lpszClassName = "AFSDWinClass";
125 return (RegisterClass(&wc));
128 /* initialize the process. Reads the init files to get the appropriate
136 TEXTMETRIC textmetric;
141 /* remember this, since it is a useful thing for some of the Windows
143 main_inst = hInstance;
145 /* create our window */
149 WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
163 /* lookup text dimensions */
165 GetTextMetrics(hDC, &textmetric);
166 nLineHeight = textmetric.tmExternalLeading + textmetric.tmHeight;
168 main_rect.left = GetDeviceCaps(hDC, LOGPIXELSX) / 4; /* 1/4 inch */
169 main_rect.right = GetDeviceCaps(hDC, HORZRES);
170 main_rect.top = GetDeviceCaps(hDC, LOGPIXELSY) / 4; /* 1/4 inch */
171 ReleaseDC(hWnd, hDC);
172 main_rect.bottom = main_rect.top + nLineHeight;
174 osi_InitPanic(afsd_notifier);
178 code = afsd_InitCM(&reason);
180 osi_panic(reason, __FILE__, __LINE__);
182 code = afsd_InitDaemons(&reason);
184 osi_panic(reason, __FILE__, __LINE__);
186 code = afsd_InitSMB(&reason, MessageBox);
188 osi_panic(reason, __FILE__, __LINE__);
190 ShowWindow(hWnd, SW_SHOWMINNOACTIVE);
195 /* called with no locks with translated messages */
196 LONG APIENTRY MainWndProc(
198 unsigned int message,
202 HDC hDC; /* display-context variable */
203 PAINTSTRUCT ps; /* paint structure */
209 /* block attempts to open the window */
213 /* LOWORD(wParam) is command */
214 return (DefWindowProc(hWnd, message, wParam, lParam));
220 hDC = BeginPaint (hWnd, &ps);
221 /* nothing to print, but this clears invalidated rectangle flag */
226 RpcMgmtStopServerListening(NULL);
231 return (DefWindowProc(hWnd, message, wParam, lParam));