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.

122 lines
2.6 KiB

  1. #include <windows.h>
  2. #include <objbase.h>
  3. #include <winnls.h>
  4. #include <commdlg.h>
  5. #include <mmsystem.h>
  6. #include <tchar.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <stdarg.h>
  10. #include <math.h>
  11. #include <string.h>
  12. #include <process.h>
  13. #include "idftest.h"
  14. #include "ourguids.h"
  15. #include "useful.h"
  16. LPCTSTR GetHResultMsg(HRESULT);
  17. int APIENTRY WinMain(HINSTANCE hInstance,
  18. HINSTANCE hPrevInstance,
  19. LPSTR lpCmdLine,
  20. int nCmdShow)
  21. {
  22. TESTCONFIGUIPARAMS p;
  23. BOOL bTCUIMsg = FALSE;
  24. HRESULT hres = S_OK;
  25. LPCTSTR title = _T("CoInitialize Result");
  26. if (SUCCEEDED(hres = CoInitialize(NULL)))
  27. {
  28. title = _T("CoCreateInstance Result");
  29. IDirectInputConfigUITest* pITest = NULL;
  30. hres = ::CoCreateInstance(CLSID_CDirectInputConfigUITest, NULL, CLSCTX_INPROC_SERVER, IID_IDirectInputConfigUITest, (LPVOID*)&pITest);
  31. if (SUCCEEDED(hres))
  32. {
  33. title = _T("TestConfigUI Result");
  34. p.dwSize = sizeof(TESTCONFIGUIPARAMS);
  35. p.eVia = TUI_VIA_CCI;
  36. p.eDisplay = TUI_DISPLAY_GDI;
  37. p.eConfigType = TUI_CONFIGTYPE_EDIT;
  38. p.nNumAcFors = 3;
  39. p.lpwszUserNames = L"Alpha\0Beta\0Gamma\0Epsilon\0Theta\0Omega\0\0";
  40. p.bEditLayout = TRUE;
  41. CopyStr(p.wszErrorText, ":)", MAX_PATH);
  42. hres = pITest->TestConfigUI(&p);
  43. bTCUIMsg = TRUE;
  44. pITest->Release();
  45. }
  46. CoUninitialize();
  47. }
  48. LPCTSTR msg = _T("Uknown Error.");
  49. switch (hres)
  50. {
  51. case S_OK: msg = _T("Success."); break;
  52. case REGDB_E_CLASSNOTREG: msg = _T("REGDB_E_CLASSNOTREG!"); break;
  53. case CLASS_E_NOAGGREGATION: msg = _T("CLASS_E_NOAGGREGATION"); break;
  54. default:
  55. msg = GetHResultMsg(hres);
  56. break;
  57. }
  58. if (FAILED(hres))
  59. {
  60. if (bTCUIMsg)
  61. {
  62. TCHAR tmsg[2048];
  63. LPTSTR tstr = AllocLPTSTR(p.wszErrorText);
  64. _stprintf(tmsg, _T("TestConfigUI() failed.\n\ntszErrorText =\n\t\"%s\"\n\n\nHRESULT...\n\n%s"), tstr, msg);
  65. free(tstr);
  66. MessageBox(NULL, msg, title, MB_OK);
  67. }
  68. else
  69. MessageBox(NULL, msg, title, MB_OK);
  70. }
  71. return 0;
  72. }
  73. LPCTSTR GetHResultMsg(HRESULT hr)
  74. {
  75. static TCHAR str[2048];
  76. LPCTSTR tszhr = NULL, tszMeaning = NULL;
  77. switch (hr)
  78. {
  79. case E_PENDING:
  80. tszhr = _T("E_PENDING");
  81. tszMeaning = _T("Data is not yet available.");
  82. break;
  83. case E_FAIL:
  84. tszhr = _T("E_FAIL");
  85. tszMeaning = _T("General failure.");
  86. break;
  87. case E_INVALIDARG:
  88. tszhr = _T("E_INVALIDARG");
  89. tszMeaning = _T("Invalid argument.");
  90. break;
  91. case E_NOTIMPL:
  92. tszhr = _T("E_NOTIMPL");
  93. tszMeaning = _T("Not implemented.");
  94. break;
  95. default:
  96. _stprintf(str, _T("Unknown HRESULT (%08X)."), hr);
  97. return str;
  98. }
  99. _stprintf(str, _T("(%08X)\n%s:\n\n%s"), hr, tszhr, tszMeaning);
  100. return str;
  101. }