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.

76 lines
1.5 KiB

  1. // This is functions used by both the
  2. // the client and the server programs
  3. #include <windows.h>
  4. #include <ole2.h>
  5. #include <stdio.h>
  6. #include <stdarg.h>
  7. #include "perror.h"
  8. LPTSTR
  9. winErrorString(
  10. HRESULT hrErrorCode,
  11. LPTSTR sBuf,
  12. int cBufSize)
  13. {
  14. #ifdef WIN32
  15. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
  16. NULL,
  17. hrErrorCode,
  18. GetSystemDefaultLangID(),
  19. sBuf,
  20. cBufSize,
  21. NULL);
  22. #else
  23. wsprintf(sBuf, "\"0x%08x\"\n", hrErrorCode);
  24. #endif // WIN32
  25. return sBuf;
  26. }
  27. #define PBUF_LEN 200
  28. #if 0 // I'm not linking with "printf" currently.
  29. void
  30. print_error(
  31. LPTSTR sMessage,
  32. HRESULT hrErrorCode)
  33. {
  34. TCHAR sBuf[PBUF_LEN];
  35. winErrorString(hrErrorCode, sMessage, PBUF_LEN);
  36. #ifdef WIN32
  37. printf("%s(0x%x)%s", sMessage, hrErrorCode, sBuf);
  38. #else
  39. printf("%s%s", sMessage, sBuf);
  40. #endif
  41. }
  42. #endif
  43. void
  44. perror_OKBox(
  45. HWND hwnd,
  46. LPTSTR sTitle,
  47. HRESULT hrErrorCode)
  48. {
  49. TCHAR sBuf[PBUF_LEN];
  50. TCHAR sBuf2[PBUF_LEN];
  51. winErrorString(hrErrorCode, sBuf, PBUF_LEN);
  52. wsprintf(sBuf2, TEXT("%s(%08x)"), sBuf, hrErrorCode);
  53. MessageBox(hwnd, sBuf2, sTitle, MB_OK);
  54. }
  55. void
  56. wprintf_OKBox(
  57. HWND hwnd,
  58. LPTSTR sTitle,
  59. LPTSTR sFormat,
  60. ...)
  61. {
  62. TCHAR sBuf[PBUF_LEN];
  63. va_list vaMarker;
  64. va_start( vaMarker, sFormat );
  65. wvsprintf(sBuf, sFormat, vaMarker);
  66. MessageBox(hwnd, sBuf, sTitle, MB_OK);
  67. }
  68.