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.

112 lines
2.6 KiB

  1. //--------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2000, Microsoft Corporation
  4. //
  5. // File: misc.c
  6. //
  7. //--------------------------------------------------------------------------
  8. #define UNICODE 1
  9. #include <stdio.h>
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <shellapi.h>
  15. #include <winldap.h>
  16. #include <stdlib.h>
  17. #include <dsgetdc.h>
  18. #include <lm.h>
  19. #include <rpc.h>
  20. #include "struct.h"
  21. #include "messages.h"
  22. #define MAX_BUF_SIZE 10000
  23. WCHAR MsgBuf[MAX_BUF_SIZE];
  24. CHAR AnsiBuf[MAX_BUF_SIZE*3];
  25. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  26. VOID
  27. MyFormatMessageText(
  28. HRESULT dwMsgId,
  29. PWSTR pszBuffer,
  30. DWORD dwBufferSize,
  31. va_list *parglist)
  32. {
  33. DWORD dwReturn = 0;
  34. dwReturn = FormatMessage(
  35. (dwMsgId >= MSG_FIRST_MESSAGE)
  36. ? FORMAT_MESSAGE_FROM_HMODULE
  37. : FORMAT_MESSAGE_FROM_SYSTEM,
  38. NULL,
  39. dwMsgId,
  40. LANG_USER_DEFAULT,
  41. pszBuffer,
  42. dwBufferSize,
  43. parglist);
  44. if (dwReturn == 0)
  45. MyPrintf(L"Formatmessage failed %d\r\n", GetLastError());
  46. }
  47. VOID
  48. ErrorMessage(
  49. IN HRESULT hr,
  50. ...)
  51. {
  52. ULONG cch;
  53. va_list arglist;
  54. va_start(arglist, hr);
  55. MyFormatMessageText(hr, MsgBuf, ARRAYLEN(MsgBuf), &arglist);
  56. cch = WideCharToMultiByte(CP_OEMCP, 0,
  57. MsgBuf, wcslen(MsgBuf),
  58. AnsiBuf, MAX_BUF_SIZE*3,
  59. NULL, NULL);
  60. WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), AnsiBuf, cch, &cch, NULL);
  61. va_end(arglist);
  62. }
  63. VOID
  64. MyPrintf(
  65. PWCHAR format,
  66. ...)
  67. {
  68. ULONG cch;
  69. va_list va;
  70. va_start(va, format);
  71. wvsprintf(MsgBuf, format, va);
  72. cch = WideCharToMultiByte(CP_OEMCP, 0,
  73. MsgBuf, wcslen(MsgBuf),
  74. AnsiBuf, MAX_BUF_SIZE*3,
  75. NULL, NULL);
  76. WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), AnsiBuf, cch, &cch, NULL);
  77. va_end(va);
  78. return;
  79. }
  80. VOID
  81. MyFPrintf(
  82. HANDLE hHandle,
  83. PWCHAR format,
  84. ...)
  85. {
  86. ULONG cch;
  87. va_list va;
  88. va_start(va, format);
  89. wvsprintf(MsgBuf, format, va);
  90. cch = WideCharToMultiByte(CP_OEMCP, 0,
  91. MsgBuf, wcslen(MsgBuf),
  92. AnsiBuf, MAX_BUF_SIZE*3,
  93. NULL, NULL);
  94. WriteFile(hHandle, AnsiBuf, cch, &cch, NULL);
  95. va_end(va);
  96. return;
  97. }