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.

106 lines
2.6 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: AppUtil.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: 2000/11/14
  10. *
  11. * DESCRIPTION: Misc application utilities
  12. *
  13. *****************************************************************************/
  14. #include <stdafx.h>
  15. #include "wiavideotest.h"
  16. /****************************Local Function Prototypes********************/
  17. ///////////////////////////////
  18. // AppUtil_ConvertToWideString
  19. //
  20. HRESULT AppUtil_ConvertToWideString(const TCHAR *pszStringToConvert,
  21. WCHAR *pwszString,
  22. UINT cchString)
  23. {
  24. HRESULT hr = S_OK;
  25. if ((pszStringToConvert == NULL) ||
  26. (pwszString == NULL))
  27. {
  28. return E_POINTER;
  29. }
  30. #ifdef UNICODE
  31. wcsncpy(pwszString, pszStringToConvert, cchString);
  32. #else
  33. MultiByteToWideChar(CP_ACP, 0, pszStringToConvert, -1,
  34. pwszString, cchString);
  35. #endif
  36. return hr;
  37. }
  38. ///////////////////////////////
  39. // AppUtil_ConvertToTCHAR
  40. //
  41. HRESULT AppUtil_ConvertToTCHAR(const WCHAR *pwszStringToConvert,
  42. TCHAR *pszString,
  43. UINT cchString)
  44. {
  45. HRESULT hr = S_OK;
  46. if ((pwszStringToConvert == NULL) ||
  47. (pszString == NULL))
  48. {
  49. return E_POINTER;
  50. }
  51. #ifdef UNICODE
  52. wcsncpy(pszString, pwszStringToConvert, cchString);
  53. #else
  54. WideCharToMultiByte(CP_ACP, 0, pwszStringToConvert,
  55. -1, pszString, cchString * sizeof(TCHAR), NULL, NULL);
  56. #endif
  57. return hr;
  58. }
  59. ///////////////////////////////
  60. // AppUtil_MsgBox
  61. //
  62. int AppUtil_MsgBox(UINT uiCaption,
  63. UINT uiTextResID,
  64. UINT uiStyle,
  65. ...)
  66. {
  67. HRESULT hr = S_OK;
  68. TCHAR szCaption[255 + 1] = {0};
  69. TCHAR szFmt[511 + 1] = {0};
  70. TCHAR szMsg[1023 + 1] = {0};
  71. int iResult = 0;
  72. va_list vArgs;
  73. if (uiCaption != 0)
  74. {
  75. iResult = LoadString(APP_GVAR.hInstance, uiCaption, szCaption,
  76. sizeof(szCaption) / sizeof(TCHAR));
  77. }
  78. if (uiTextResID != 0)
  79. {
  80. iResult = LoadString(APP_GVAR.hInstance, uiTextResID, szFmt,
  81. sizeof(szFmt) / sizeof(TCHAR));
  82. }
  83. va_start(vArgs, uiStyle);
  84. _vsntprintf(szMsg, sizeof(szMsg) / sizeof(TCHAR), szFmt, vArgs);
  85. va_end(vArgs);
  86. return MessageBox(APP_GVAR.hwndMainDlg, szMsg, szCaption, uiStyle);
  87. }