Source code of Windows XP (NT5)
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.

291 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. SMVDrv.cpp
  5. Abstract:
  6. This executable works as a driver for the SMVTest.exe.
  7. Author:
  8. Diaa Fathalla (DiaaF) 10-Dec-2000
  9. Revision History:
  10. DiaaF 18-Apr-2001 Adding GUI interface
  11. --*/
  12. #include "stdafx.h"
  13. #include "resource.h"
  14. /*
  15. * Global Variables
  16. */
  17. HINSTANCE g_hInstance;
  18. BOOL CallSMVTest()
  19. {
  20. CLog Log;
  21. DWORD dwSignalled = 0;
  22. DWORD dwExitCode = 0;
  23. HANDLE hEventObjects[1];
  24. PROCESS_INFORMATION ProcessID;
  25. STARTUPINFO sui = { sizeof(STARTUPINFO),
  26. 0,
  27. NULL,
  28. NULL,
  29. NULL,
  30. 0,
  31. 0,
  32. 0,
  33. 0,
  34. 0,
  35. 0,
  36. 0,
  37. 0,
  38. 0,
  39. 0 };
  40. TCHAR sz_CommandLine[MAX_PATH];
  41. GetCurrentDirectory(MAX_PATH, sz_CommandLine);
  42. _tcscat(sz_CommandLine, TEXT("\\SMVTest.exe"));
  43. //Start running SMVTest
  44. if(!::CreateProcess (NULL,
  45. sz_CommandLine,
  46. NULL,
  47. NULL,
  48. FALSE,
  49. NORMAL_PRIORITY_CLASS | CREATE_SUSPENDED,
  50. NULL,
  51. NULL,
  52. &sui,
  53. &ProcessID))
  54. {
  55. Log.LogResults(FALSE, TEXT("Can't create process for SMVTest.exe"));
  56. return FALSE;
  57. }
  58. //Set the Event to the current Process
  59. hEventObjects[0] = ProcessID.hThread;
  60. ResumeThread(ProcessID.hThread);
  61. dwSignalled = !WAIT_OBJECT_0;
  62. do
  63. {
  64. dwSignalled = WaitForSingleObject(hEventObjects[0],0);
  65. }
  66. //Wait for the 'First' event which is the only one available.
  67. while (dwSignalled != WAIT_OBJECT_0);
  68. GetExitCodeProcess(ProcessID.hProcess, &dwExitCode);
  69. //Close the thread/process handles
  70. CloseHandle(ProcessID.hProcess);
  71. CloseHandle(ProcessID.hThread);
  72. if(dwExitCode != 0)
  73. Log.LogResults(FALSE, TEXT("SMVTest.exe returned failure."));
  74. return TRUE;
  75. }
  76. /*++
  77. It initializes the project's log file and copy the shim dlls
  78. to the AppPatch folder.
  79. --*/
  80. BOOL Initialize()
  81. {
  82. CLog Log;
  83. TCHAR szAppPatchFolder[MAX_PATH];
  84. TCHAR szShimCurrentDir[MAX_PATH];
  85. TCHAR sz_SMVTSTSrcPath[MAX_PATH];
  86. TCHAR sz_SMVTST2SrcPath[MAX_PATH];
  87. TCHAR sz_SMVTSTDstPath[MAX_PATH];
  88. TCHAR sz_SMVTST2DstPath[MAX_PATH];
  89. Log.InitLogfile();
  90. GetWindowsDirectory(szAppPatchFolder, MAX_PATH);
  91. _tcscat(szAppPatchFolder, TEXT("\\AppPatch"));
  92. _tcscpy(sz_SMVTSTDstPath, szAppPatchFolder);
  93. _tcscpy(sz_SMVTST2DstPath, szAppPatchFolder);
  94. GetCurrentDirectory(MAX_PATH, szShimCurrentDir);
  95. _tcscat(szShimCurrentDir, TEXT("\\TestShims"));
  96. _tcscpy(sz_SMVTSTSrcPath, szShimCurrentDir);
  97. _tcscpy(sz_SMVTST2SrcPath, szShimCurrentDir);
  98. _tcscat(sz_SMVTSTSrcPath, TEXT("\\_SMVTST.DLL"));
  99. _tcscat(sz_SMVTST2SrcPath, TEXT("\\_SMVTST2.DLL"));
  100. _tcscat(sz_SMVTSTDstPath, TEXT("\\_SMVTST.DLL"));
  101. _tcscat(sz_SMVTST2DstPath, TEXT("\\_SMVTST2.DLL"));
  102. //Copy the _SMVTST and _SMVTST2 to the AppPatch folder.
  103. CopyFile(sz_SMVTSTSrcPath, sz_SMVTSTDstPath, FALSE);
  104. CopyFile(sz_SMVTST2SrcPath, sz_SMVTST2DstPath, FALSE);
  105. return TRUE;
  106. }
  107. /*++
  108. It uninitializes the project's log file and delete the shim dlls
  109. from the AppPatch folder.
  110. --*/
  111. BOOL Uninitialize()
  112. {
  113. CLog Log;
  114. TCHAR szAppPatchFolder[MAX_PATH];
  115. TCHAR sz_SMVTSTDstPath[MAX_PATH];
  116. TCHAR sz_SMVTST2DstPath[MAX_PATH];
  117. GetWindowsDirectory(szAppPatchFolder, MAX_PATH);
  118. _tcscat(szAppPatchFolder, TEXT("\\AppPatch"));
  119. _tcscpy(sz_SMVTSTDstPath, szAppPatchFolder);
  120. _tcscpy(sz_SMVTST2DstPath, szAppPatchFolder);
  121. _tcscat(sz_SMVTSTDstPath, TEXT("\\_SMVTST.DLL"));
  122. _tcscat(sz_SMVTST2DstPath, TEXT("\\_SMVTST2.DLL"));
  123. //Delete the shim DLLs from the AppPatch Folder
  124. DeleteFile(sz_SMVTSTDstPath);
  125. DeleteFile(sz_SMVTST2DstPath);
  126. Log.EndLogfile();
  127. return TRUE;
  128. }
  129. /*++
  130. SetEnvironmentVariables: Sets necessary Environment Variables.
  131. --*/
  132. BOOL SetEnvironmentVariables()
  133. {
  134. TCHAR sz_Buffer[] = _T("9");
  135. DWORD dwReturnValue;
  136. HKEY hKey= NULL;
  137. long lRet= 0;
  138. TCHAR sz_SubKey[] = _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment");
  139. CLog Log;
  140. lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sz_SubKey, 0, KEY_WRITE, &hKey);
  141. if(lRet == ERROR_SUCCESS)
  142. {
  143. lRet = RegSetValueEx(hKey,_T("SHIM_DEBUG_LEVEL"), 0, REG_SZ,
  144. (LPBYTE) sz_Buffer, sizeof(sz_Buffer));
  145. if(lRet == ERROR_SUCCESS)
  146. SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,(LPARAM) _T("Environment"),
  147. SMTO_ABORTIFHUNG, 5000, &dwReturnValue);
  148. else
  149. Log.LogResults(FALSE,TEXT("Can't set the environment variable SHIM_DEBUG_LEVEL"));
  150. RegCloseKey(hKey);
  151. }
  152. return TRUE;
  153. }
  154. BOOL CALLBACK
  155. SMVDrvDlgProc(
  156. HWND hDlg,
  157. UINT uMsg,
  158. WPARAM wParam,
  159. LPARAM lParam)
  160. /*++
  161. SMVDrvDlgProc
  162. Description: The dialog proc of SMVDrv.
  163. --*/
  164. {
  165. switch (uMsg) {
  166. case WM_INITDIALOG:
  167. SetClassLong(hDlg, GCL_HICON, (LONG) LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_SMV)));
  168. //g_bGoodApp = FALSE;
  169. //CheckRadioButton(hDlg, IDC_OPTION_GOOD, IDC_OPTION_BAD, IDC_OPTION_BAD);
  170. SetEnvironmentVariables();
  171. break;
  172. case WM_COMMAND:
  173. switch (LOWORD (wParam))
  174. {
  175. case IDCANCEL:
  176. EndDialog(hDlg, TRUE);
  177. return TRUE;
  178. case IDRUN:
  179. Initialize();
  180. CallSMVTest();
  181. Uninitialize();
  182. break;
  183. //case IDC_OPTION_GOOD:
  184. //case IDC_OPTION_BAD:
  185. // CheckRadioButton(hDlg, IDC_OPTION_GOOD, IDC_OPTION_BAD, LOWORD(wParam));
  186. // g_bGoodApp = !g_bGoodApp;
  187. // return TRUE;
  188. }
  189. default:
  190. return FALSE;
  191. }
  192. return FALSE;
  193. }
  194. int APIENTRY WinMain(HINSTANCE hInstance,
  195. HINSTANCE hPrevInstance,
  196. LPSTR lpCmdLine,
  197. int nCmdShow)
  198. /*++
  199. It initializes the project's log file and copy the shim dlls
  200. to the AppPatch folder.
  201. --*/
  202. {
  203. switch(*lpCmdLine)
  204. {
  205. //
  206. // Check for the command line options
  207. //
  208. case '/':
  209. case '-':
  210. switch(*(lpCmdLine+1))
  211. {
  212. //Quite Mode
  213. case 'q':
  214. case 'Q':
  215. Initialize();
  216. SetEnvironmentVariables();
  217. CallSMVTest();
  218. Uninitialize();
  219. break;
  220. }
  221. break;
  222. default:
  223. //
  224. // If no command line options, launch dialog.
  225. //
  226. g_hInstance = hInstance;
  227. DialogBox(hInstance,
  228. MAKEINTRESOURCE(IDD_SMVDRV),
  229. GetDesktopWindow(),
  230. SMVDrvDlgProc);
  231. }
  232. return 0;
  233. }