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.

863 lines
24 KiB

  1. //+---------------------------------------------------------------------------
  2. // Copyright (C) 1991, Microsoft Corporation.
  3. //
  4. // File: assert.cxx
  5. //
  6. // Contents: Debugging output routines for idsmgr.dll
  7. //
  8. // Functions: Assert
  9. // PopUpError
  10. //
  11. // History: 23-Jul-91 KyleP Created.
  12. // 09-Oct-91 KevinRo Major changes and comments added
  13. // 18-Oct-91 vich moved debug print routines out
  14. // 10-Jun-92 BryanT Switched to w4crt.h instead of wchar.h
  15. // 30-Sep-93 KyleP DEVL obsolete
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma hdrstop
  19. //
  20. // This one file **always** uses debugging options
  21. //
  22. #if DBG == 1
  23. #include <stdarg.h>
  24. #include <stdio.h>
  25. #include <dprintf.h> // w4printf, w4dprintf prototypes
  26. #include <debnot.h>
  27. #include <olesem.hxx>
  28. #include <windows.h>
  29. #include <netevent.h>
  30. #include <stackwalk.h>
  31. #include <asrtcfg.h>
  32. #include <privguid.h>
  33. #include <memapi.hxx>
  34. unsigned long Win4InfoLevel = DEF_INFOLEVEL;
  35. unsigned long Win4InfoMask = 0xffffffff;
  36. BOOL gAssertOnCreate = TRUE;
  37. int ForceAV();
  38. //+---------------------------------------------------------------------------
  39. //
  40. // Function: _asdprintf
  41. //
  42. // Synopsis: Calls vdprintf to output a formatted message.
  43. //
  44. // History: 18-Oct-91 vich Created
  45. //
  46. //----------------------------------------------------------------------------
  47. inline void __cdecl
  48. _asdprintf(
  49. char const *pszfmt, ...)
  50. {
  51. va_list va;
  52. va_start(va, pszfmt);
  53. vdprintf(DEB_FORCE, "Assert", pszfmt, va);
  54. va_end(va);
  55. }
  56. typedef enum
  57. {
  58. ASSRTCFG_BREAK = 0x01,
  59. ASSRTCFG_POPUP = 0x02,
  60. ASSRTCFG_DEBUGMESSAGE = 0x04,
  61. ASSRTCFG_PRINTSTACK = 0x08,
  62. ASSRTCFG_USEAV = 0x10
  63. } ASSRTCFG;
  64. //+---------------------------------------------------------------------
  65. //
  66. // Class: CAssertInfo
  67. //
  68. // Synopsis: Data type to trake assertion and logging parameters
  69. //
  70. // History: 27-Jan-99 MattSmit Created
  71. //
  72. //----------------------------------------------------------------------
  73. class CAssertInfo : public IAssertConfig
  74. {
  75. public:
  76. CAssertInfo() : _dwFlags(ASSRTCFG_POPUP | ASSRTCFG_DEBUGMESSAGE) {}
  77. //
  78. // IUnknown
  79. //
  80. STDMETHOD(QueryInterface)(REFIID riid, PVOID * ppv)
  81. {
  82. if ((IsEqualIID(riid, IID_IUnknown)) ||
  83. (IsEqualIID(riid, IID_IAssertConfig)))
  84. {
  85. *ppv = this;
  86. AddRef();
  87. return S_OK;
  88. }
  89. else
  90. {
  91. return E_NOINTERFACE;
  92. }
  93. }
  94. STDMETHOD_(ULONG, AddRef)() { return 1;}
  95. STDMETHOD_(ULONG, Release)() { return 1;}
  96. //
  97. // IConfigAssert
  98. //
  99. STDMETHOD(SetBreak)(BOOL f) { SetFlag(f, ASSRTCFG_BREAK); return S_OK;}
  100. STDMETHOD(SetPopup)(BOOL f) { SetFlag(f, ASSRTCFG_POPUP); return S_OK;}
  101. STDMETHOD(SetDebuggerMessage)(BOOL f) { SetFlag(f, ASSRTCFG_DEBUGMESSAGE); return S_OK;}
  102. STDMETHOD(SetPrintStack)(BOOL f) { SetFlag(f, ASSRTCFG_PRINTSTACK); return S_OK;}
  103. STDMETHOD(SetUseAV)(BOOL f) { SetFlag(f, ASSRTCFG_USEAV); return S_OK;}
  104. STDMETHOD(SetLog)(ASSRTLOGINFO *pLogInfo) { _logInfo = *pLogInfo; return S_OK;}
  105. STDMETHOD(SetContextString)(char *psz){ _pszContext = psz; return S_OK;}
  106. STDMETHOD(SetThreshold)(ULONG cTh) { _cThreshold = cTh; return S_OK;}
  107. //
  108. // helpers
  109. //
  110. void Win4AssertEx(char const * szFile, int iLine, char const * szMessage);
  111. int PopUpError(char const *szMsg, int iLine, char const *szFile);
  112. void ComposeErrorMessage(char const *szMsg, int iLine, char const *szFile);
  113. void AppendToFile(char *pszFileName, char const *pwszData);
  114. void FatalErrorHandler(char *errmsg);
  115. void LogAssertionFailure(char const * szMessage);
  116. private:
  117. void SetFlag(BOOL f, DWORD bit)
  118. {
  119. _dwFlags = f ? _dwFlags | bit : _dwFlags & ~bit;
  120. }
  121. char *GetStack();
  122. BOOL GetBreak() {return _dwFlags | ASSRTCFG_BREAK;}
  123. BOOL GetPopup() {return _dwFlags | ASSRTCFG_POPUP;}
  124. BOOL GetDebugMessage() {return _dwFlags | ASSRTCFG_DEBUGMESSAGE;}
  125. void BreakIntoDebugger()
  126. {
  127. if (_dwFlags & ASSRTCFG_USEAV)
  128. ForceAV();
  129. else
  130. DebugBreak();
  131. }
  132. DWORD _dwFlags; // what to do when an assertion fails
  133. ASSRTLOGINFO _logInfo; // if/where to write a log entry
  134. char *_pszContext; // user supplied context string for the log
  135. char _errMessage[128]; // generated error string
  136. ULONG _cThreshold; // number of assertion to ignore
  137. ULONG _cAssrtFail; // number of assertion failures so far
  138. };
  139. CAssertInfo gAssertInfo;
  140. //+---------------------------------------------------------------------------
  141. //
  142. // Method: Win4AssertEx
  143. //
  144. // Synopsis: Called on assertion failure. Takes appropriate action based
  145. // on member variables
  146. //
  147. // History: 27-Jan-99 MattSmit Created
  148. //
  149. //----------------------------------------------------------------------------
  150. void CAssertInfo::Win4AssertEx(
  151. char const * szFile,
  152. int iLine,
  153. char const * szMessage)
  154. {
  155. _cAssrtFail++;
  156. if (_cAssrtFail < _cThreshold)
  157. {
  158. return;
  159. }
  160. ComposeErrorMessage(szMessage, iLine, szFile);
  161. BOOL fBrokeAlready = FALSE;
  162. if (_dwFlags & ASSRTCFG_DEBUGMESSAGE)
  163. {
  164. DWORD tid = GetCurrentThreadId();
  165. _asdprintf("%s\n%s\n", _errMessage, szMessage);
  166. }
  167. if (_logInfo.dwDest & ASSRTLOG_FILE)
  168. {
  169. AppendToFile(_logInfo.pszFileName, szMessage);
  170. }
  171. if (_logInfo.dwDest & ASSRTLOG_NTEVENTLOG)
  172. {
  173. LogAssertionFailure(szMessage);
  174. }
  175. if (_dwFlags & ASSRTCFG_POPUP)
  176. {
  177. int id = PopUpError(szMessage, iLine, szFile);
  178. if (id == IDCANCEL)
  179. {
  180. fBrokeAlready = TRUE;
  181. BreakIntoDebugger();
  182. }
  183. }
  184. if ((_dwFlags & ASSRTCFG_BREAK) && !fBrokeAlready)
  185. {
  186. BreakIntoDebugger();
  187. }
  188. }
  189. //+------------------------------------------------------------
  190. // Method: PopUpError
  191. //
  192. // Synopsis: Displays a dialog box using provided text,
  193. // and presents the user with the option to
  194. // continue or cancel.
  195. //
  196. // Arguments:
  197. // szMsg -- The string to display in main body of dialog
  198. // iLine -- Line number of file in error
  199. // szFile -- Filename of file in error
  200. //
  201. // Returns:
  202. // IDCANCEL -- User selected the CANCEL button
  203. // IDOK -- User selected the OK button
  204. //-------------------------------------------------------------
  205. int CAssertInfo::PopUpError(char const *szMsg, int iLine, char const *szFile)
  206. {
  207. int id;
  208. WCHAR wszWinsta[64];
  209. HWINSTA hWinsta;
  210. DWORD Size;
  211. DWORD dwMessageFlags = MB_SETFOREGROUND | MB_TASKMODAL |
  212. MB_ICONEXCLAMATION | MB_OKCANCEL;
  213. hWinsta = GetProcessWindowStation();
  214. Size = sizeof(wszWinsta);
  215. wszWinsta[0] = 0;
  216. if ( hWinsta )
  217. {
  218. (void) GetUserObjectInformation(
  219. hWinsta,
  220. UOI_NAME,
  221. wszWinsta,
  222. Size,
  223. &Size );
  224. }
  225. //
  226. // This makes popups from non-interactive servers/services (including
  227. // rpcss) visible.
  228. //
  229. if ( wszWinsta[0] && (lstrcmpiW(wszWinsta,L"Winsta0") != 0) )
  230. dwMessageFlags |= MB_SERVICE_NOTIFICATION | MB_DEFAULT_DESKTOP_ONLY;
  231. id = MessageBoxA(NULL,(char *) szMsg, (LPSTR) _errMessage,
  232. dwMessageFlags);
  233. // If id == 0, then an error occurred. There are two possibilities
  234. // that can cause the error: Access Denied, which means that this
  235. // process does not have access to the default desktop, and everything
  236. // else (usually out of memory). Oh well.
  237. return id;
  238. }
  239. //+---------------------------------------------------------------------------
  240. //
  241. // Method: ComposeErrorMessage
  242. //
  243. // Synopsis: Put together a message that contains useful info about the
  244. // context of the error
  245. //
  246. // History: 27-Jan-99 MattSmit Created
  247. //
  248. //----------------------------------------------------------------------------
  249. void CAssertInfo::ComposeErrorMessage(
  250. char const *szMsg,
  251. int iLine,
  252. char const *szFile)
  253. {
  254. static char szModuleName[128];
  255. DWORD tid = GetCurrentThreadId();
  256. DWORD pid = GetCurrentProcessId();
  257. char * pszModuleName;
  258. BOOL bStatus;
  259. if (GetModuleFileNameA(NULL, szModuleName, 128))
  260. {
  261. pszModuleName = strrchr(szModuleName, '\\');
  262. if (!pszModuleName)
  263. {
  264. pszModuleName = szModuleName;
  265. }
  266. else
  267. {
  268. pszModuleName++;
  269. }
  270. }
  271. else
  272. {
  273. pszModuleName = "Unknown";
  274. }
  275. wsprintfA(_errMessage,"Process: %s File: %s line %u, thread id %d.%d",
  276. pszModuleName, szFile, iLine, pid, tid);
  277. }
  278. //+---------------------------------------------------------------------------
  279. //
  280. // Method: AppendToFile
  281. //
  282. // Synopsis: Write assertion failures to a log file.
  283. //
  284. // History: 27-Jan-99 MattSmit Created
  285. //
  286. //----------------------------------------------------------------------------
  287. void CAssertInfo::AppendToFile(char *pszFileName, char const *pwszData)
  288. {
  289. HANDLE hFile = CreateFileA(pszFileName,
  290. GENERIC_WRITE,
  291. 0,
  292. NULL,
  293. OPEN_ALWAYS,
  294. FILE_ATTRIBUTE_NORMAL,
  295. NULL);
  296. if (hFile == INVALID_HANDLE_VALUE)
  297. {
  298. FatalErrorHandler("Could not open log File.");
  299. }
  300. DWORD ret = SetFilePointer(hFile, 0, 0, FILE_END);
  301. if (ret == -1)
  302. {
  303. FatalErrorHandler("Could not set file pointer.");
  304. }
  305. DWORD dwBytesWritten;
  306. BOOL ok = WriteFile(hFile, _errMessage,
  307. lstrlenA(_errMessage),
  308. &dwBytesWritten, NULL);
  309. if (!ok)
  310. {
  311. FatalErrorHandler("Could not write to log File.");
  312. }
  313. ok = WriteFile(hFile, "\n", 1,
  314. &dwBytesWritten, NULL);
  315. if (!ok)
  316. {
  317. FatalErrorHandler("Could not write to log File.");
  318. }
  319. ok = WriteFile(hFile, pwszData,
  320. lstrlenA(pwszData),
  321. &dwBytesWritten, NULL);
  322. if (!ok)
  323. {
  324. FatalErrorHandler("Could not write to log File.");
  325. }
  326. ok = WriteFile(hFile, "\n", 1,
  327. &dwBytesWritten, NULL);
  328. if (!ok)
  329. {
  330. FatalErrorHandler("Could not write to log File.");
  331. }
  332. if (_dwFlags & ASSRTCFG_PRINTSTACK)
  333. {
  334. char *psz = GetStack();
  335. if (psz)
  336. {
  337. ok = WriteFile(hFile, psz,
  338. lstrlenA(psz),
  339. &dwBytesWritten, NULL);
  340. if (!ok)
  341. {
  342. FatalErrorHandler("Could not write to log File.");
  343. }
  344. PrivMemFree(psz);
  345. }
  346. }
  347. if (_pszContext)
  348. {
  349. ok = WriteFile(hFile, pwszData,
  350. lstrlenA(pwszData),
  351. &dwBytesWritten, NULL);
  352. if (!ok)
  353. {
  354. FatalErrorHandler("Could not write to log File.");
  355. }
  356. ok = WriteFile(hFile, "\n", 1,
  357. &dwBytesWritten, NULL);
  358. if (!ok)
  359. {
  360. FatalErrorHandler("Could not write to log File.");
  361. }
  362. }
  363. CloseHandle(hFile);
  364. }
  365. //+---------------------------------------------------------------------------
  366. //
  367. // Function: GetStackExceptionFilter
  368. //
  369. // Synopsis: Walk stack and store in a string variable
  370. //
  371. // History: 27-Jan-99 MattSmit Created
  372. //
  373. //----------------------------------------------------------------------------
  374. extern HRESULT CStackWalkerCF_CreateInstance (IUnknown *pUnkOuter, REFIID riid, void** ppv);
  375. LONG GetStackExceptionFilter(LPEXCEPTION_POINTERS lpep, char **ppStack)
  376. {
  377. HRESULT hr;
  378. LONG lRet = EXCEPTION_EXECUTE_HANDLER;
  379. IStackWalker* pIStackWalker = NULL;
  380. IStackWalkerStack* pIStack = NULL;
  381. *ppStack = NULL;
  382. DWORD dwFault = lpep->ExceptionRecord->ExceptionCode;
  383. if (dwFault != 0xceadbeef)
  384. {
  385. lRet = EXCEPTION_CONTINUE_SEARCH;
  386. goto Cleanup;
  387. }
  388. hr = CStackWalkerCF_CreateInstance (NULL, IID_IStackWalker, (void**) &pIStackWalker);
  389. if (FAILED (hr))
  390. goto Cleanup;
  391. hr = pIStackWalker->Attach (NULL);
  392. if (FAILED (hr))
  393. goto Cleanup;
  394. pIStack = pIStackWalker->CreateStackTrace (lpep->ContextRecord, NULL, 0);
  395. if (!pIStack)
  396. goto Cleanup;
  397. SIZE_T nLen = pIStack->Size (20);
  398. WCHAR * szStack = new WCHAR[nLen];
  399. if (szStack)
  400. {
  401. if (pIStack->GetStack (nLen, szStack, 20))
  402. {
  403. *ppStack = (char *) PrivMemAlloc(nLen);
  404. if (*ppStack)
  405. {
  406. wcstombs(*ppStack, szStack, lstrlenW(szStack));
  407. }
  408. }
  409. delete [] szStack;
  410. }
  411. Cleanup:
  412. if (pIStackWalker)
  413. pIStackWalker->Release();
  414. if (pIStack)
  415. pIStack->Release();
  416. return lRet;
  417. }
  418. //+---------------------------------------------------------------------------
  419. //
  420. // Method: GetStack
  421. //
  422. // Synopsis: Throws and exception so the filter can get stack info
  423. //
  424. // History: 27-Jan-99 MattSmit Created
  425. //
  426. //----------------------------------------------------------------------------
  427. char *CAssertInfo::GetStack()
  428. {
  429. char *pStack = NULL;
  430. __try
  431. {
  432. RaiseException(0xceadbeef, 0, 0, NULL);
  433. }
  434. __except(GetStackExceptionFilter(GetExceptionInformation(), &pStack))
  435. {
  436. }
  437. return pStack;
  438. }
  439. //+---------------------------------------------------------------------------
  440. //
  441. // Method: FatalErrorHandler
  442. //
  443. // Synopsis: Called when the assertion code itself cannot allocate
  444. // enough resources to log the assertion failure.
  445. //
  446. // History: 27-Jan-99 MattSmit Created
  447. //
  448. //----------------------------------------------------------------------------
  449. void CAssertInfo::FatalErrorHandler(char *szMessage)
  450. {
  451. BOOL fBrokeAlready = FALSE;
  452. lstrcpyA(_errMessage, "Fatal error while processing assertion failure");
  453. _asdprintf("%s\n%s\n", _errMessage, szMessage);
  454. if (_dwFlags & ASSRTCFG_POPUP)
  455. {
  456. int id = PopUpError(szMessage, __LINE__, __FILE__);
  457. if (id == IDCANCEL)
  458. {
  459. fBrokeAlready = TRUE;
  460. BreakIntoDebugger();
  461. }
  462. }
  463. if (_dwFlags & ASSRTCFG_BREAK && !fBrokeAlready)
  464. {
  465. BreakIntoDebugger();
  466. }
  467. }
  468. //+---------------------------------------------------------------------------
  469. //
  470. // Method: LogAssertionFailure
  471. //
  472. // Synopsis: Write and assertion failure to the NT event log
  473. //
  474. // History: 27-Jan-99 MattSmit Created
  475. //
  476. //----------------------------------------------------------------------------
  477. void CAssertInfo::LogAssertionFailure(char const * szMessage)
  478. {
  479. HANDLE LogHandle;
  480. char const * Strings[3]; // array of message strings.
  481. Strings[0] = _errMessage;
  482. Strings[1] = szMessage;
  483. Strings[2] = _pszContext ? _pszContext : "";
  484. // Get the log handle, then report the event.
  485. LogHandle = RegisterEventSource( NULL, L"DCOM" );
  486. if ( LogHandle )
  487. {
  488. ReportEventA( LogHandle,
  489. EVENTLOG_ERROR_TYPE,
  490. 0, // event category
  491. EVENT_DCOM_ASSERTION_FAILURE,
  492. NULL,
  493. 3, // 3 strings passed
  494. 0, // 0 bytes of binary
  495. Strings, // array of strings
  496. NULL ); // no raw data
  497. // clean up the event log handle
  498. DeregisterEventSource(LogHandle);
  499. }
  500. else
  501. {
  502. FatalErrorHandler("Could not register as event source");
  503. }
  504. }
  505. //+------------------------------------------------------------
  506. // Function: vdprintf
  507. //
  508. // Synopsis: Prints debug output using a pointer to the
  509. // variable information. Used primarily by the
  510. // xxDebugOut macros
  511. //
  512. // Arguements:
  513. // ulCompMask -- Component level mask used to determine
  514. // output ability
  515. // pszComp -- String const of component prefix.
  516. // ppszfmt -- Pointer to output format and data
  517. //
  518. //-------------------------------------------------------------
  519. //
  520. // This semaphore is *outside* vdprintf because the compiler isn't smart
  521. // enough to serialize access for construction if it's function-local and
  522. // protected by a guard variable.
  523. //
  524. // KyleP - 20 May, 1993
  525. //
  526. COleStaticMutexSem g_mxsVdprintf;
  527. BOOL g_mxsVdprintfInitialized = TRUE;
  528. STDAPI_(void) vdprintf(
  529. unsigned long ulCompMask,
  530. char const *pszComp,
  531. char const *ppszfmt,
  532. va_list pargs)
  533. {
  534. if ((ulCompMask & DEB_FORCE) == DEB_FORCE ||
  535. ((ulCompMask | Win4InfoLevel) & Win4InfoMask))
  536. {
  537. if ((Win4InfoLevel & (DEB_DBGOUT | DEB_STDOUT)) != DEB_STDOUT)
  538. {
  539. if (! (ulCompMask & DEB_NOCOMPNAME))
  540. {
  541. DWORD tid = GetCurrentThreadId();
  542. DWORD pid = GetCurrentProcessId();
  543. if (g_mxsVdprintfInitialized)
  544. LOCK (g_mxsVdprintf);
  545. w4dprintf( "%d.%03dp> ", pid, tid );
  546. w4dprintf("%s: ", pszComp);
  547. w4vdprintf(ppszfmt, pargs);
  548. if (g_mxsVdprintfInitialized)
  549. UNLOCK (g_mxsVdprintf);
  550. }
  551. }
  552. }
  553. }
  554. //+---------------------------------------------------------------------------
  555. //
  556. // Function: ForceAV
  557. //
  558. // Synopsis: Cause and Access Violation
  559. //
  560. // History: 27-Jan-99 MattSmit Created
  561. //
  562. //----------------------------------------------------------------------------
  563. int ForceAV()
  564. {
  565. return *((int *) 0);
  566. }
  567. //+---------------------------------------------------------------------------
  568. //
  569. // Function: _Win4Assert, private
  570. //
  571. // Synopsis: Display assertion information
  572. //
  573. // Effects: Called when an assertion is hit.
  574. //
  575. // History: 12-Jul-91 AlexT Created.
  576. // 05-Sep-91 AlexT Catch Throws and Catches
  577. // 19-Oct-92 HoiV Added events for TOM
  578. //
  579. //----------------------------------------------------------------------------
  580. STDAPI_(void) Win4AssertEx(
  581. char const * szFile,
  582. int iLine,
  583. char const * szMessage)
  584. {
  585. gAssertInfo.Win4AssertEx(szFile, iLine, szMessage);
  586. }
  587. //+------------------------------------------------------------
  588. // Function: SetWin4InfoLevel(unsigned long ulNewLevel)
  589. //
  590. // Synopsis: Sets the global info level for debugging output
  591. // Returns: Old info level
  592. //
  593. //-------------------------------------------------------------
  594. EXPORTIMP unsigned long APINOT
  595. SetWin4InfoLevel(
  596. unsigned long ulNewLevel)
  597. {
  598. unsigned long ul;
  599. ul = Win4InfoLevel;
  600. Win4InfoLevel = ulNewLevel;
  601. return(ul);
  602. }
  603. //+------------------------------------------------------------
  604. // Function: _SetWin4InfoMask(unsigned long ulNewMask)
  605. //
  606. // Synopsis: Sets the global info mask for debugging output
  607. // Returns: Old info mask
  608. //
  609. //-------------------------------------------------------------
  610. EXPORTIMP unsigned long APINOT
  611. SetWin4InfoMask(
  612. unsigned long ulNewMask)
  613. {
  614. unsigned long ul;
  615. ul = Win4InfoMask;
  616. Win4InfoMask = ulNewMask;
  617. return(ul);
  618. }
  619. //+---------------------------------------------------------------------------
  620. //
  621. // Function: ReadINIFile
  622. //
  623. // Synopsis: Get a paremeter value from the win.ini file
  624. //
  625. // History: 27-Jan-99 MattSmit Created
  626. //
  627. //----------------------------------------------------------------------------
  628. BOOL ReadINIFile(char * pszKey, BOOL * pVal)
  629. {
  630. static char szValue[128];
  631. if (GetProfileStringA("CairOLE Assertions", // section
  632. pszKey, // key
  633. "", // default value
  634. szValue, // return buffer
  635. 128))
  636. {
  637. *pVal = (lstrcmpiA(szValue, "yes") == 0) ;
  638. return TRUE;
  639. }
  640. return FALSE;
  641. }
  642. //+---------------------------------------------------------------------------
  643. //
  644. // Function: AssertDebugInit
  645. //
  646. // Synopsis: Initialize the assertion data structure using the win.ini file
  647. //
  648. // History: 27-Jan-99 MattSmit Created
  649. //
  650. //----------------------------------------------------------------------------
  651. void AssertDebugInit()
  652. {
  653. #define ASSERT_SET(key) \
  654. { \
  655. BOOL val; \
  656. if (ReadINIFile(#key, &val)) \
  657. { \
  658. gAssertInfo.Set##key(val); \
  659. } \
  660. } \
  661. static char szValue[128];
  662. ASSERT_SET(Break);
  663. ASSERT_SET(Popup);
  664. ASSERT_SET(DebuggerMessage);
  665. ASSERT_SET(PrintStack);
  666. ASSERT_SET(UseAV);
  667. ASSRTLOGINFO logInfo;
  668. memset(&logInfo, 0, sizeof(logInfo));
  669. if (GetProfileStringA("CairOLE Assertions", // section
  670. "Log_File", // key
  671. "", // default value
  672. logInfo.pszFileName, // return buffer
  673. MAX_PATH))
  674. {
  675. if (lstrcmpA("", logInfo.pszFileName) != 0)
  676. {
  677. logInfo.dwDest |= ASSRTLOG_FILE;
  678. }
  679. }
  680. if (GetProfileStringA("CairOLE Assertions", // section
  681. "Log_NtEventLog", // key
  682. "", // default value
  683. szValue, // return buffer
  684. 128))
  685. {
  686. logInfo.dwDest |= (lstrcmpiA(szValue, "yes") == 0 )? ASSRTLOG_NTEVENTLOG : 0;
  687. }
  688. if (logInfo.dwDest)
  689. {
  690. gAssertInfo.SetLog(&logInfo);
  691. }
  692. if (GetProfileStringA("CairOLE Assertions", // section
  693. "AssertOnCreate", // key
  694. "", // default value
  695. szValue, // return buffer
  696. 128))
  697. {
  698. gAssertOnCreate = FALSE;
  699. }
  700. }
  701. //+---------------------------------------------------------------------------
  702. //
  703. // Function: CoGetAssertConfig
  704. //
  705. // Synopsis: CI for CAssertInfo. gAssertInfo is a singleton,
  706. // so just to a QI
  707. //
  708. // History: 27-Jan-99 MattSmit Created
  709. //
  710. //----------------------------------------------------------------------------
  711. HRESULT CoGetAssertConfig(REFIID riid, PVOID *ppv)
  712. {
  713. return gAssertInfo.QueryInterface(riid, ppv);
  714. }
  715. #else
  716. int assertDontUseThisName(void)
  717. {
  718. return 1;
  719. }
  720. #endif // DBG == 1