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.

227 lines
7.5 KiB

  1. //=--------------------------------------------------------------------------=
  2. // Debug.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // contains various methods that will only really see any use in DEBUG builds
  13. //
  14. #include "pch.h"
  15. #ifdef DEBUG
  16. #include <stdlib.h>
  17. //=--------------------------------------------------------------------------=
  18. // Private Constants
  19. //---------------------------------------------------------------------------=
  20. //
  21. static const char szFormat[] = "%s\nFile %s, Line %d";
  22. static const char szFormat2[] = "%s\n%s\nFile %s, Line %d";
  23. #define _SERVERNAME_ "ActiveX Framework"
  24. #define CTL_INI_SIZE 14
  25. static const char szTitle[] = _SERVERNAME_ " Assertion (Abort = UAE, Retry = INT 3, Ignore = Continue)";
  26. //=--------------------------------------------------------------------------=
  27. // Local functions
  28. //=--------------------------------------------------------------------------=
  29. int NEAR _IdMsgBox(LPSTR pszText, LPCSTR pszTitle, UINT mbFlags);
  30. //=--------------------------------------------------------------------------=
  31. // DisplayAssert
  32. //=--------------------------------------------------------------------------=
  33. // Display an assert message box with the given pszMsg, pszAssert, source
  34. // file name, and line number. The resulting message box has Abort, Retry,
  35. // Ignore buttons with Abort as the default. Abort does a FatalAppExit;
  36. // Retry does an int 3 then returns; Ignore just returns.
  37. //
  38. VOID DisplayAssert
  39. (
  40. LPSTR pszMsg,
  41. LPSTR pszAssert,
  42. LPSTR pszFile,
  43. UINT line
  44. )
  45. {
  46. LPTSTR lpszText;
  47. char szMsg[512];
  48. lpszText = pszMsg; // Assume no file & line # info
  49. // If C file assert, where you've got a file name and a line #
  50. //
  51. if (pszFile) {
  52. // Then format the assert nicely
  53. //
  54. wsprintf(szMsg, szFormat, (pszMsg&&*pszMsg) ? pszMsg : pszAssert, pszFile, line);
  55. lpszText = szMsg;
  56. }
  57. // Put up a dialog box
  58. //
  59. switch (_IdMsgBox(lpszText, szTitle, MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SYSTEMMODAL)) {
  60. case IDABORT:
  61. FatalAppExit(0, lpszText);
  62. return;
  63. case IDRETRY:
  64. // call the win32 api to break us.
  65. //
  66. DebugBreak();
  67. return;
  68. }
  69. return;
  70. }
  71. //=---------------------------------------------------------------------------=
  72. // Beefed-up version of WinMessageBox.
  73. //=---------------------------------------------------------------------------=
  74. //
  75. int NEAR _IdMsgBox
  76. (
  77. LPSTR pszText,
  78. LPCSTR pszTitle,
  79. UINT mbFlags
  80. )
  81. {
  82. HWND hwndActive;
  83. MSG msg;
  84. int id;
  85. hwndActive = GetActiveWindow();
  86. id = MessageBox(hwndActive, pszText, pszTitle, mbFlags);
  87. if(PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE))
  88. {
  89. id = MessageBox(hwndActive, pszText, pszTitle, mbFlags);
  90. PostMessage(msg.hwnd, msg.message, msg.wParam, msg.lParam);
  91. }
  92. return id;
  93. }
  94. //---------------------------------------------------------------------------
  95. // Implementation for class CtlSwitch
  96. //---------------------------------------------------------------------------
  97. CtlSwitch* CtlSwitch::g_pctlswFirst = NULL;
  98. //=---------------------------------------------------------------------------=
  99. // CtlSwitch::InitSwitch - Initialize members and add new object to
  100. // linked-list
  101. //=---------------------------------------------------------------------------=
  102. void CtlSwitch::InitSwitch
  103. (
  104. char * pszName
  105. )
  106. {
  107. // set fields
  108. m_pszName = pszName;
  109. m_fSet = FALSE;
  110. // link into global list of switches
  111. this->m_pctlswNext = g_pctlswFirst;
  112. g_pctlswFirst = this;
  113. }
  114. //=---------------------------------------------------------------------------=
  115. // SetCtlSwitches:
  116. // Initialize linked-list control switches to those values set in the
  117. // corresponding .ini files
  118. //=---------------------------------------------------------------------------=
  119. VOID SetCtlSwitches
  120. (
  121. LPSTR lpCtlPath
  122. )
  123. {
  124. TCHAR lpWindowsDir[128]; // Path to Windows directory
  125. UINT uMaxWinPathSize = 128; // Max size for Win path
  126. UINT uPathSize; // Actual Win path size
  127. LPCTSTR lpAllSwitch = "allctls"; // Name of section which applies to all ctls
  128. char lpszCtlName[128]; // Name of ctl (minus extension) to act as section name in INI
  129. LPCTSTR lpFileName = "\\CtlSwtch.ini"; // Name of INI file
  130. char lpStatus[4]; // Status of switch (on/off)
  131. LPCTSTR lpDefaultStatus = "set"; // Default status
  132. LPCTSTR lpTurnOff = "off";
  133. LPCTSTR lpTurnOn = "on";
  134. DWORD nSizeStatus = 4; // Size of status switch
  135. DWORD fSet; // If switch is set in INI
  136. // Create path to CtlSwtch.ini in the Windows directory
  137. uPathSize = GetWindowsDirectory(lpWindowsDir, uMaxWinPathSize) + CTL_INI_SIZE;
  138. lstrcat(lpWindowsDir, lpFileName);
  139. // Create section name for control (control name minus extension)
  140. lstrcpyn(lpszCtlName, lpCtlPath, strlen(lpCtlPath) - 3);
  141. int curChar = strlen(lpszCtlName);
  142. int charCount = 0;
  143. while (lpszCtlName[curChar] != '\\')
  144. {
  145. curChar--;
  146. charCount++;
  147. }
  148. curChar++;
  149. lstrcpyn(lpszCtlName, &lpCtlPath[curChar], charCount);
  150. // Use CTLSWTCH.INI to set switches. If not defined in INI file, create switch
  151. for (CtlSwitch* pctlsw = CtlSwitch::g_pctlswFirst; pctlsw; pctlsw = pctlsw->m_pctlswNext)
  152. {
  153. // Specific control switches override the "allctls" switch
  154. fSet = GetPrivateProfileString(lpszCtlName, (LPCTSTR)pctlsw->m_pszName, lpDefaultStatus, (LPTSTR)lpStatus, nSizeStatus, (LPCTSTR)lpWindowsDir);
  155. // If switch is not set for control, use "allctls" switch
  156. if ((fSet == 0) || (strcmp(lpStatus, "set") == 0))
  157. {
  158. fSet = GetPrivateProfileString(lpAllSwitch, (LPCTSTR)pctlsw->m_pszName, lpDefaultStatus, (LPTSTR)lpStatus, nSizeStatus, (LPCTSTR)lpWindowsDir);
  159. // If INI file or switch do not exist, create one...
  160. if ((fSet == 0) || (strcmp(lpStatus, "set") == 0))
  161. {
  162. // If switch was initialized TRUE, turn it on
  163. if (pctlsw->m_fSet != 0)
  164. WritePrivateProfileString(lpszCtlName, (LPCTSTR)pctlsw->m_pszName, (LPTSTR)lpTurnOn, (LPCTSTR)lpWindowsDir);
  165. // Else turn it off
  166. else
  167. {
  168. WritePrivateProfileString(lpAllSwitch, (LPCTSTR)pctlsw->m_pszName, (LPTSTR)lpTurnOff, (LPCTSTR)lpWindowsDir);
  169. WritePrivateProfileString(lpszCtlName, (LPCTSTR)pctlsw->m_pszName, (LPTSTR)lpTurnOff, (LPCTSTR)lpWindowsDir);
  170. pctlsw->m_fSet = FALSE;
  171. }
  172. }
  173. else if ((strcmp(lpStatus, "on") == 0))
  174. {
  175. WritePrivateProfileString(lpszCtlName, (LPCTSTR)pctlsw->m_pszName, (LPTSTR)lpStatus, (LPCTSTR)lpWindowsDir);
  176. pctlsw->m_fSet = TRUE;
  177. }
  178. else
  179. {
  180. WritePrivateProfileString(lpszCtlName, (LPCTSTR)pctlsw->m_pszName, (LPTSTR)lpTurnOff, (LPCTSTR)lpWindowsDir);
  181. pctlsw->m_fSet = FALSE;
  182. }
  183. }
  184. else if ((strcmp(lpStatus, "on") == 0))
  185. pctlsw->m_fSet = TRUE;
  186. else
  187. pctlsw->m_fSet = FALSE;
  188. }
  189. }
  190. #endif