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.

96 lines
3.2 KiB

  1. /*****************************************************************************
  2. Natural Language Group Common Library
  3. CMN_OutputDebugStringW.c -
  4. DEBUG ONLY
  5. local helper functions that puts specific error message to debug output
  6. for errors on library functions
  7. History:
  8. DougP 9/9/97 Created
  9. The end user license agreement (EULA) for CSAPI, CHAPI, or CTAPI covers this source file. Do not disclose it to third parties.
  10. You are not entitled to any support or assistance from Microsoft Corporation regarding your use of this program.
  11. 1997-1998 Microsoft Corporation. All rights reserved.
  12. ******************************************************************************/
  13. #include "precomp.h"
  14. #if defined(_DEBUG)
  15. #undef CMN_OutputDebugStringW
  16. VOID
  17. WINAPI
  18. CMN_OutputDebugStringW(const WCHAR * pwzOutputString)
  19. {
  20. #if defined(_M_IX86)
  21. char szOutputString[MAX_PATH];
  22. BOOL fcharerr;
  23. char chdef = '?';
  24. int res = WideCharToMultiByte (CP_ACP, 0, pwzOutputString,
  25. -1,
  26. szOutputString, sizeof(szOutputString), &chdef, &fcharerr);
  27. OutputDebugStringA(szOutputString);
  28. #else
  29. OutputDebugStringW(pwzOutputString);
  30. #endif
  31. }
  32. void WINAPI CMN_OutputSystemErrA(const char *pszMsg, const char *pszComponent)
  33. {
  34. CMN_OutputErrA(GetLastError(), pszMsg, pszComponent);
  35. }
  36. void WINAPI CMN_OutputErrA(DWORD dwErr, const char *pszMsg, const char *pszComponent)
  37. {
  38. char szMsgBuf[256];
  39. OutputDebugStringA(pszMsg);
  40. OutputDebugStringA(" \"");
  41. if (pszComponent)
  42. OutputDebugStringA(pszComponent);
  43. OutputDebugStringA("\": ");
  44. if (!FormatMessageA(
  45. FORMAT_MESSAGE_FROM_SYSTEM, // source and processing options
  46. NULL, // pointer to message source
  47. dwErr, // requested message identifier
  48. 0, // language identifier for requested message
  49. szMsgBuf, // pointer to message buffer
  50. sizeof(szMsgBuf)/sizeof(szMsgBuf[0]), // maximum size of message buffer
  51. 0 // address of array of message inserts
  52. ))
  53. OutputDebugStringA("Couldn't decode err msg");
  54. else
  55. OutputDebugStringA(szMsgBuf);
  56. OutputDebugStringA("\r\n");
  57. }
  58. void WINAPI CMN_OutputSystemErrW(const WCHAR *pwzMsg, const WCHAR *pwzComponent)
  59. {
  60. CMN_OutputErrW(GetLastError(), pwzMsg, pwzComponent);
  61. }
  62. void WINAPI CMN_OutputErrW(DWORD dwErr, const WCHAR *pwzMsg, const WCHAR *pwzComponent)
  63. {
  64. char wcMsgBuf[256];
  65. CMN_OutputDebugStringW(pwzMsg);
  66. OutputDebugStringA(" \"");
  67. if (pwzComponent)
  68. CMN_OutputDebugStringW(pwzComponent);
  69. OutputDebugStringA("\": ");
  70. if (!FormatMessageA(
  71. FORMAT_MESSAGE_FROM_SYSTEM, // source and processing options
  72. NULL, // pointer to message source
  73. dwErr, // requested message identifier
  74. 0, // language identifier for requested message
  75. wcMsgBuf, // pointer to message buffer
  76. sizeof(wcMsgBuf)/sizeof(wcMsgBuf[0]), // maximum size of message buffer
  77. 0 // address of array of message inserts
  78. ))
  79. OutputDebugStringA("Couldn't decode err msg");
  80. else
  81. OutputDebugStringA(wcMsgBuf);
  82. OutputDebugStringA("\r\n");
  83. }
  84. #endif // _DEBUG