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.

163 lines
4.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: debug.cxx
  7. //
  8. // Contents: Message routines.
  9. //
  10. // Functions: SchMsg and SchError.
  11. //
  12. // History: 09-Sep-95 EricB Created.
  13. // 01-Dec-95 MarkBl Split from util.cxx.
  14. // 29-Feb-01 JBenton Prefix Bug 294884
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "..\pch\headers.hxx"
  18. #pragma hdrstop
  19. #include "..\inc\resource.h"
  20. #include "..\inc\common.hxx"
  21. #include "..\inc\debug.hxx"
  22. #define ARRAYLEN(a) (sizeof(a) / sizeof((a)[0]))
  23. //+----------------------------------------------------------------------------
  24. //
  25. // Message and error reporting functions
  26. //
  27. //-----------------------------------------------------------------------------
  28. //+----------------------------------------------------------------------------
  29. //
  30. // Function: SchMsg
  31. //
  32. // Synopsis: Display a message.
  33. //
  34. // Arguments: [ptszMsg] - a string message
  35. // [iStringID] - a string resource ID
  36. // [...] - optional params
  37. //
  38. // Notes: Either a string or a string ID must be supplied, but not both.
  39. // If there are optional params, it is assumed that the string has
  40. // type conversion placeholders so that the string can be used as
  41. // a formating string.
  42. //-----------------------------------------------------------------------------
  43. void
  44. SchMsg(TCHAR * ptszMsg, int iStringID, ...)
  45. {
  46. TCHAR tszFmt[SCH_BIGBUF_LEN], tszMsg[SCH_XBIGBUF_LEN];
  47. if (iStringID != 0)
  48. {
  49. if (!LoadString(g_hInstance, iStringID, tszFmt, SCH_BIGBUF_LEN - 1))
  50. {
  51. lstrcpy(tszMsg,
  52. TEXT("unknown error (failed to load string resource)"));
  53. }
  54. }
  55. else
  56. {
  57. if (lstrlen(ptszMsg) >= SCH_BIGBUF_LEN)
  58. {
  59. lstrcpyn(tszFmt, ptszMsg, SCH_BIGBUF_LEN - 1);
  60. tszFmt[SCH_BIGBUF_LEN - 1] = L'\0';
  61. }
  62. else
  63. {
  64. lstrcpy(tszFmt, ptszMsg);
  65. }
  66. }
  67. va_list va;
  68. va_start(va, iStringID);
  69. wvsprintf(tszMsg, tszFmt, va);
  70. va_end(va);
  71. #if DBG == 1
  72. #ifdef UNICODE
  73. char szMsg[SCH_XBIGBUF_LEN];
  74. ZeroMemory(szMsg, ARRAYLEN(szMsg));
  75. (void) UnicodeToAnsi(szMsg, tszMsg, SCH_XBIGBUF_LEN);
  76. lstrcatA(szMsg, "\n"); // TODO: length checking
  77. schDebugOut((DEB_ITRACE, szMsg));
  78. #else
  79. lstrcat(tszMsg, "\n");
  80. schDebugOut((DEB_ITRACE, tszMsg));
  81. #endif
  82. #endif
  83. MessageBox(NULL, tszMsg, TEXT("Scheduling Agent Service"),
  84. MB_ICONINFORMATION); // TODO: string resource
  85. }
  86. //+----------------------------------------------------------------------------
  87. //
  88. // Function: SchError
  89. //
  90. // Synopsis: error reporting
  91. //
  92. // Arguments: [iStringID] - a string resource ID
  93. // [iParam] - an optional error value
  94. //
  95. // Notes: If iParam is non-zero, it is assumed that the string has a
  96. // type conversion placeholder so that the string can be used as
  97. // a formating string.
  98. //-----------------------------------------------------------------------------
  99. void
  100. SchError(int iStringID, int iParam)
  101. {
  102. TCHAR tszMsg[SCH_DB_BUFLEN + 1], tszFormat[SCH_DB_BUFLEN + 1],
  103. tszTitle[SCH_MEDBUF_LEN + 1];
  104. const TCHAR tszErr[] = TEXT("ERROR: ");
  105. WORD cch;
  106. cch = (WORD)LoadString(g_hInstance, IDS_ERRMSG_PREFIX, tszMsg, SCH_DB_BUFLEN);
  107. if (cch == 0)
  108. {
  109. // Use literal if the string resource load failed.
  110. //
  111. lstrcpy(tszMsg, tszErr);
  112. cch = (WORD)lstrlen(tszErr);
  113. }
  114. if (!LoadString(g_hInstance, iStringID, tszMsg + cch,
  115. SCH_DB_BUFLEN - cch))
  116. {
  117. wcsncpy(tszMsg + cch,
  118. TEXT("unknown error (failed to load string resource)"),
  119. SCH_DB_BUFLEN - cch);
  120. tszMsg[SCH_DB_BUFLEN] = '\0';
  121. iParam = 0;
  122. }
  123. if (iParam != 0)
  124. {
  125. lstrcpy(tszFormat, tszMsg);
  126. //
  127. // Note that there is no length checking below...
  128. //
  129. wsprintf(tszMsg, tszFormat, iParam);
  130. }
  131. if (!LoadString(g_hInstance, IDS_SCHEDULER_NAME, tszTitle, SCH_MEDBUF_LEN))
  132. {
  133. lstrcpy(tszTitle, TEXT("Scheduling Agent"));
  134. }
  135. #if DBG == 1
  136. #ifdef UNICODE
  137. char szMsg[SCH_DB_BUFLEN];
  138. ZeroMemory(szMsg, ARRAYLEN(szMsg));
  139. (void) UnicodeToAnsi(szMsg, tszMsg, SCH_DB_BUFLEN);
  140. lstrcatA(szMsg, "\n"); // TODO: length checking
  141. schDebugOut((DEB_ERROR, szMsg));
  142. #else
  143. lstrcat(tszMsg, "\n");
  144. schDebugOut((DEB_ITRACE, tszMsg));
  145. #endif
  146. #endif
  147. MessageBox(NULL, tszMsg, tszTitle, MB_ICONEXCLAMATION);
  148. }