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.

140 lines
3.4 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include "restok.h"
  4. #include "showerrs.h"
  5. extern UCHAR szDHW[];
  6. extern CHAR szAppName[];
  7. //............................................................
  8. void ShowEngineErr( int n, void *p1, void *p2)
  9. {
  10. CHAR *pMsg = NULL;
  11. CHAR *pArg[2];
  12. pArg[0] = p1;
  13. pArg[1] = p2;
  14. if ( B_FormatMessage( (FORMAT_MESSAGE_MAX_WIDTH_MASK & 78)
  15. | FORMAT_MESSAGE_FROM_HMODULE
  16. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  17. NULL,
  18. (DWORD)n,
  19. szDHW,
  20. DHWSIZE,
  21. (va_list *)pArg) )
  22. {
  23. RLMessageBoxA( szDHW);
  24. }
  25. else
  26. {
  27. sprintf( szDHW,
  28. "Internal error: FormatMessage call failed: msg %d: err %Lu",
  29. n,
  30. GetLastError());
  31. RLMessageBoxA( szDHW);
  32. }
  33. }
  34. //...................................................................
  35. void ShowErr( int n, void *p1, void *p2)
  36. {
  37. CHAR *pMsg = NULL;
  38. CHAR *pArg[2];
  39. pArg[0] = p1;
  40. pArg[1] = p2;
  41. pMsg = GetErrMsg( n);
  42. if ( ! pMsg )
  43. {
  44. pMsg = "Internal error: UNKNOWN ERROR MESSAGE id# %1!d!";
  45. pArg[0] = IntToPtr(n);
  46. }
  47. if ( pMsg )
  48. {
  49. if ( FormatMessageA( FORMAT_MESSAGE_MAX_WIDTH_MASK | 72
  50. | FORMAT_MESSAGE_FROM_STRING
  51. | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  52. pMsg,
  53. 0,
  54. 0,
  55. szDHW,
  56. DHWSIZE,
  57. (va_list *)pArg) )
  58. {
  59. RLMessageBoxA( szDHW);
  60. }
  61. else
  62. {
  63. RLMessageBoxA( "Internal error: FormatMessage call failed");
  64. }
  65. }
  66. else
  67. {
  68. RLMessageBoxA( "Internal error: GetErrMsg call failed");
  69. }
  70. }
  71. //............................................................
  72. CHAR *GetErrMsg( UINT uErrID)
  73. {
  74. static CHAR szBuf[ 1024];
  75. int n = LoadStringA( NULL, uErrID, szBuf, sizeof( szBuf));
  76. return( n ? szBuf : NULL);
  77. }
  78. //.......................................................
  79. //...
  80. //... Bi-Lingual FormatMessage
  81. DWORD B_FormatMessage(
  82. DWORD dwFlags,
  83. LPCVOID lpSource,
  84. DWORD dwMessageId,
  85. LPSTR lpBuffer,
  86. DWORD nSize,
  87. va_list *Arguments )
  88. {
  89. DWORD ret;
  90. //... Look for message in current locale
  91. if ( !(ret = FormatMessageA( dwFlags,
  92. lpSource,
  93. dwMessageId,
  94. LOWORD( GetThreadLocale()),
  95. lpBuffer,
  96. nSize,
  97. Arguments)) )
  98. {
  99. //... Not found, so look for US English message
  100. if ( GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND )
  101. {
  102. return( FormatMessageA( dwFlags,
  103. lpSource,
  104. dwMessageId,
  105. 0x0409L,
  106. lpBuffer,
  107. nSize,
  108. Arguments) );
  109. }
  110. }
  111. return( ret);
  112. }