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.

143 lines
2.5 KiB

  1. #include "precomp.h"
  2. UINT APIENTRY
  3. get_str_id (
  4. ENUM_TO_STR Array[],
  5. ULONG ArraySz,
  6. ULONG EnumVal
  7. ) {
  8. ULONG i;
  9. for (i=0; (i<ArraySz) && (Array->enumVal!=EnumVal); i++, Array++) ;
  10. if (i<ArraySz)
  11. return Array->strId;
  12. else
  13. return (UINT)(-1);
  14. }
  15. BOOL APIENTRY
  16. get_enum_val (
  17. HINSTANCE hModule,
  18. ENUM_TO_STR Array[],
  19. ULONG ArraySz,
  20. LPTSTR String,
  21. PULONG EnumVal
  22. ) {
  23. ULONG i;
  24. TCHAR buffer[MAX_VALUE];
  25. for (i=0; (i<ArraySz)
  26. && (_tcsicmp (
  27. String,
  28. GetString (
  29. hModule,
  30. Array->strId,
  31. buffer
  32. )
  33. )!=0); i++, Array++) ;
  34. if (i<ArraySz) {
  35. *EnumVal = Array->enumVal;
  36. return TRUE;
  37. }
  38. else
  39. return FALSE;
  40. }
  41. ULONG APIENTRY
  42. put_msg (
  43. HINSTANCE hModule,
  44. UINT MsgId,
  45. ...
  46. ) {
  47. DWORD msglen;
  48. LPTSTR vp;
  49. va_list arglist;
  50. va_start (arglist, MsgId);
  51. msglen = FormatMessage(
  52. FORMAT_MESSAGE_FROM_HMODULE |
  53. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  54. hModule,
  55. MsgId,
  56. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  57. (LPTSTR)&vp,
  58. 0,
  59. &arglist);
  60. if (msglen != 0) {
  61. _fputts (vp, stdout);
  62. LocalFree(vp);
  63. }
  64. va_end (arglist);
  65. return msglen;
  66. }
  67. ULONG APIENTRY
  68. put_str_msg (
  69. HINSTANCE hModule,
  70. UINT StrId,
  71. ...
  72. ) {
  73. DWORD msglen;
  74. static TCHAR buffer[MAX_STR_MESSAGE];
  75. LPTSTR vp;
  76. va_list arglist;
  77. va_start (arglist, StrId);
  78. msglen = FormatMessage(
  79. FORMAT_MESSAGE_FROM_STRING |
  80. FORMAT_MESSAGE_ALLOCATE_BUFFER,
  81. GetString (hModule,StrId,buffer),
  82. 0,
  83. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  84. (LPTSTR)&vp,
  85. 0,
  86. &arglist);
  87. if (msglen != 0) {
  88. _fputts (vp, stdout);
  89. LocalFree(vp);
  90. }
  91. va_end (arglist);
  92. return msglen;
  93. }
  94. ULONG APIENTRY
  95. put_error_msg (
  96. DWORD error
  97. ) {
  98. LPWSTR vp;
  99. DWORD msglen;
  100. if ((msglen=FormatMessageW (
  101. FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER,
  102. NULL,
  103. error,
  104. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language
  105. (LPWSTR)&vp,
  106. 0,
  107. NULL))>0) {
  108. fputws (vp, stdout);
  109. LocalFree (vp);
  110. return msglen;
  111. }
  112. else if (MprAdminGetErrorString (error, &vp)==NO_ERROR) {
  113. msglen = wcslen (vp);
  114. fputws (vp, stdout);
  115. MprAdminBufferFree (vp);
  116. return msglen;
  117. }
  118. else if (MprAdminGetErrorString (error, &vp)==NO_ERROR) {
  119. msglen = wcslen (vp);
  120. fputws (vp, stdout);
  121. MprAdminBufferFree (vp);
  122. return msglen;
  123. }
  124. else
  125. return 0;
  126. }