Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. spcimain.c
  5. Abstract:
  6. This module contains the main entry point for the user mode portion of SoftPCI
  7. Author:
  8. Brandon Allsop (BrandonA)
  9. Revision History:
  10. --*/
  11. #include "pch.h"
  12. BOOL
  13. SoftPCI_RegisterClasses(
  14. VOID
  15. );
  16. VOID
  17. SoftPCI_ParseArgs(
  18. IN PWCHAR ArgList
  19. );
  20. // Instance handle of this application.
  21. HINSTANCE g_Instance;
  22. HWND g_SoftPCIMainWnd;
  23. HWND g_TreeViewWnd;
  24. HANDLE g_DriverHandle;
  25. const WCHAR g_SoftPCIMainClassName[] = L"SoftPciMainClass";
  26. const WCHAR g_SoftPCIDevPropClassName[] = L"SoftPciDevPropClass";
  27. INT
  28. APIENTRY
  29. WinMain(
  30. IN HINSTANCE Instance,
  31. IN HINSTANCE PrevInstance,
  32. IN LPSTR CmdLine,
  33. IN INT CmdShow
  34. )
  35. {
  36. MSG msg;
  37. HWND popupWnd;
  38. PSINGLE_LIST_ENTRY listEntry;
  39. g_Instance = Instance;
  40. InitCommonControls();
  41. if ((g_SoftPCIMainWnd = FindWindow(g_SoftPCIMainClassName, NULL)) != NULL){
  42. if (IsIconic(g_SoftPCIMainWnd)){
  43. ShowWindow(g_SoftPCIMainWnd, SW_RESTORE);
  44. }else {
  45. BringWindowToTop(g_SoftPCIMainWnd);
  46. if ((popupWnd = GetLastActivePopup(g_SoftPCIMainWnd)) != g_SoftPCIMainWnd)
  47. BringWindowToTop(popupWnd);
  48. SetForegroundWindow(popupWnd);
  49. }
  50. return 0;
  51. }
  52. if (!SoftPCI_RegisterClasses()) return 0;
  53. //
  54. // Register for hotplug driver event notification
  55. //
  56. SoftPCI_RegisterHotplugEvents();
  57. //
  58. // Try and open a handle to our driver. If this fails then the user will have the
  59. // option from the "OPTIONS" menu to install SoftPCI support. If we succeed then we
  60. // disable this option.
  61. //
  62. g_DriverHandle = SoftPCI_OpenHandleToDriver();
  63. //
  64. // The command line is supplied in ANSI format only at the WinMain entry
  65. // point. When running in UNICODE, we ask for the command line in UNICODE from
  66. // Windows directly.
  67. //
  68. SoftPCI_ParseArgs(GetCommandLine());
  69. //
  70. // If we have any script devices to install then do so now.
  71. //
  72. SoftPCI_InstallScriptDevices();
  73. if ((g_SoftPCIMainWnd = SoftPCI_CreateMainWnd()) != NULL){
  74. UpdateWindow(g_SoftPCIMainWnd);
  75. while (GetMessage(&msg, NULL, 0, 0)) {
  76. TranslateMessage(&msg);
  77. DispatchMessage(&msg);
  78. }
  79. }
  80. return 0;
  81. }
  82. BOOL
  83. SoftPCI_RegisterClasses(VOID)
  84. /*++
  85. Routine Description:
  86. Registers SoftPCI main window class
  87. Arguments:
  88. none
  89. Return Value:
  90. TRUE on success
  91. --*/
  92. {
  93. WNDCLASS wndClass;
  94. wndClass.style = CS_DBLCLKS | CS_BYTEALIGNWINDOW | CS_GLOBALCLASS;
  95. wndClass.lpfnWndProc = SoftPCI_MainWndProc;
  96. wndClass.cbClsExtra = 0;
  97. wndClass.cbWndExtra = 0;
  98. wndClass.hInstance = g_Instance;
  99. wndClass.hIcon = LoadIcon(g_Instance, MAKEINTRESOURCE(IDI_SPCI));
  100. wndClass.hCursor = LoadCursor(g_Instance, MAKEINTRESOURCE(IDC_SPLIT));
  101. wndClass.hbrBackground = (HBRUSH) (COLOR_3DSHADOW + 1);
  102. //WndClass.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
  103. wndClass.lpszMenuName = MAKEINTRESOURCE(IDM_SPCI);
  104. wndClass.lpszClassName = g_SoftPCIMainClassName;
  105. return RegisterClass(&wndClass);
  106. }
  107. VOID
  108. SoftPCI_ParseArgs(
  109. IN PWCHAR CommandLine
  110. )
  111. /*++
  112. Routine Description:
  113. This routine takes our command line information and parses out what we care about.
  114. Arguments:
  115. CommandLine - Null terminated string containing out command line
  116. Return Value:
  117. TRUE if we have args that allow us to continue running
  118. --*/
  119. {
  120. PWCHAR p = CommandLine, p2 = NULL;
  121. WCHAR pathToIni[MAX_PATH];
  122. //
  123. // First make sure everything is lowercase
  124. //
  125. _wcslwr(CommandLine);
  126. if (((p = wcsstr(CommandLine, L"-s")) != NULL) ||
  127. ((p = wcsstr(CommandLine, L"/s")) != NULL)){
  128. if (g_DriverHandle == NULL) {
  129. MessageBox(
  130. NULL,
  131. L"Cannot process script file! SoftPCI support not installed!",
  132. L"Script Error",
  133. MB_OK
  134. );
  135. }
  136. //
  137. // We found an Install command line.
  138. //
  139. p += wcslen(L"-s");
  140. //
  141. // Parse out the specified ini path
  142. //
  143. if ((*p == '=') || (*p == ':')) {
  144. p++;
  145. p2 = pathToIni;
  146. while (*p && (*p != ' ')) {
  147. *p2 = *p;
  148. p2++;
  149. p++;
  150. }
  151. *p2 = 0;
  152. if (!SoftPCI_BuildDeviceInstallList(pathToIni)){
  153. SoftPCI_MessageBox(L"Error Parsing Script File!",
  154. L"%s\n",
  155. g_ScriptError
  156. );
  157. }
  158. }
  159. }
  160. }// SoftPCI_ParseArgs