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.

190 lines
4.8 KiB

  1. // AppReport.cpp : Implementation of CAppReport
  2. #include "stdafx.h"
  3. #include "Appcompr.h"
  4. #include "AppReport.h"
  5. #include "progview.h"
  6. #include "upload.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CAppReport
  9. STDMETHODIMP CAppReport::BrowseForExecutable(
  10. BSTR bstrWinTitle,
  11. BSTR bstrPreviousPath,
  12. VARIANT *bstrExeName
  13. )
  14. {
  15. WCHAR NameBuffer[MAX_PATH]={0};
  16. WCHAR Filter[MAX_PATH];
  17. OPENFILENAMEW FileToOpen;
  18. BOOL result;
  19. HWND hParent;
  20. BOOL bNT4 = FALSE;
  21. DWORD dwVersion = GetVersion();
  22. DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
  23. CComBSTR WindowText = L"AppCompat Report Proto - Microsoft Internet Explorer";
  24. CComBSTR FileName = L"";
  25. if (dwWindowsMajorVersion < 5)
  26. {
  27. ::MessageBoxW(NULL,L"Invalid OS",NULL,MB_OK);
  28. }
  29. if (dwVersion < 0x80000000)
  30. {
  31. if (dwWindowsMajorVersion == 4)
  32. bNT4 = TRUE;
  33. }
  34. GetWindowHandle(WindowText, &hParent);
  35. if (bNT4)
  36. {
  37. FileToOpen.lStructSize = sizeof(OPENFILENAME);
  38. }
  39. else
  40. {
  41. FileToOpen.lStructSize = sizeof (OPENFILENAMEW);
  42. }
  43. FileToOpen.hwndOwner = hParent;
  44. FileToOpen.hInstance = NULL;
  45. StringCbCopyW(Filter, sizeof(Filter), L"Executable Files;*.exe");
  46. Filter[16] = L'\0'; Filter[23]=L'\0'; // make a multi-string
  47. FileToOpen.lpstrFilter = Filter;
  48. FileToOpen.lpstrCustomFilter = NULL;
  49. FileToOpen.nMaxCustFilter = 0;
  50. FileToOpen.nFilterIndex = 1;
  51. if (bstrPreviousPath == NULL)
  52. {
  53. bstrPreviousPath = L"";
  54. }
  55. StringCbCopyW(NameBuffer, sizeof(NameBuffer), bstrPreviousPath);
  56. FileToOpen.lpstrFile = NameBuffer;
  57. FileToOpen.nMaxFile = MAX_PATH;
  58. FileToOpen.lpstrFileTitle = NULL;
  59. FileToOpen.lpstrInitialDir = NULL;
  60. FileToOpen.lpstrTitle = L"Application Not Compatible";
  61. FileToOpen.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST ;
  62. FileToOpen.lpstrDefExt = NULL;
  63. FileToOpen.lCustData = 0L;
  64. FileToOpen.lpfnHook = NULL;
  65. result = GetOpenFileNameW(&FileToOpen);
  66. if (!result)
  67. {
  68. bstrExeName->vt = VT_BSTR;
  69. bstrExeName->bstrVal = FileName.Detach();
  70. return S_OK;
  71. }
  72. else
  73. {
  74. FileName = FileToOpen.lpstrFile;
  75. bstrExeName->vt = VT_BSTR;
  76. bstrExeName->bstrVal = FileName.Detach();
  77. }
  78. return S_OK;
  79. }
  80. STDMETHODIMP CAppReport::GetApplicationFromList(
  81. BSTR bstrTitle,
  82. VARIANT *bstrExeName
  83. )
  84. {
  85. ULONG res;
  86. HWND hParent;
  87. WCHAR wszAppName[MAX_PATH];
  88. CComBSTR FileName = L"";
  89. GetWindowHandle(NULL, &hParent);
  90. wszAppName[0] = 0;
  91. res = (ULONG) DialogBoxParamW(::_Module.GetModuleInstance(),
  92. MAKEINTRESOURCEW(IDD_PROGRAM_LIST_DIALOG),
  93. hParent,
  94. Dialog_GetProgFromList,
  95. (LPARAM) wszAppName);
  96. if (res == IDOK)
  97. {
  98. FileName = wszAppName;
  99. }
  100. bstrExeName->vt = VT_BSTR;
  101. bstrExeName->bstrVal = FileName.Detach();
  102. return S_OK;
  103. }
  104. STDMETHODIMP CAppReport::CreateReport(BSTR bstrTitle, BSTR bstrProblemType, BSTR bstrComment, BSTR bstrACWResult,
  105. BSTR bstrAppName, VARIANT *DwResult)
  106. {
  107. LPWSTR wszAppCompatText = NULL;
  108. HRESULT hr;
  109. OSVERSIONINFO OsVer = {0};
  110. DwResult->vt = VT_INT;
  111. DwResult->intVal = 0;
  112. OsVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  113. GetVersionEx(&OsVer);
  114. if ((OsVer.dwMajorVersion < 5) ||
  115. (OsVer.dwMajorVersion == 5 && OsVer.dwMinorVersion == 0))
  116. {
  117. DwResult->intVal = ERROR_APPRPT_OS_NOT_SUPPORTED;
  118. return S_OK;
  119. }
  120. // Generate app compat text file using apphelp.dll
  121. __try {
  122. hr = GenerateAppCompatText(bstrAppName, &wszAppCompatText);
  123. } __except (EXCEPTION_EXECUTE_HANDLER) {
  124. hr = E_FAIL;
  125. }
  126. if (hr != S_OK)
  127. {
  128. DwResult->intVal = ERROR_APPRPT_COMPAT_TEXT;
  129. return S_OK;
  130. }
  131. // Send error report using faultrep.dll
  132. hr = UploadAppProblem(bstrAppName, bstrProblemType, bstrComment,
  133. bstrACWResult,
  134. wszAppCompatText);
  135. if (FAILED(hr))
  136. {
  137. hr = ERROR_APPRPT_UPLOADING;
  138. }
  139. DwResult->intVal = hr;
  140. return S_OK;
  141. }
  142. HRESULT
  143. CAppReport::GetWindowHandle(
  144. LPWSTR wszWinTitle,
  145. HWND* phwnd
  146. )
  147. {
  148. *phwnd = ::GetActiveWindow();
  149. if (*phwnd == NULL)
  150. {
  151. ::MessageBoxW(NULL, L"No active window", NULL, MB_OK);
  152. }
  153. *phwnd = ::GetForegroundWindow();
  154. return S_OK;
  155. WCHAR Title[MAX_PATH];
  156. ::GetWindowTextW(*phwnd, Title, sizeof(Title)/sizeof(WCHAR));
  157. ::MessageBoxW(NULL, Title, NULL, MB_OK);
  158. }