home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / DLLTRAC.PAK / TRACE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.9 KB  |  175 lines

  1. // trace.cpp : Contains TRACE.DLL implementation and initialization
  2. //              code.
  3. //
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1995 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include <afxwin.h>
  15. #include "traceapi.h"
  16. #include "traceres.h"       // trace resources
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Dialog class
  20.  
  21. class CPromptDlg : public CDialog
  22. {
  23. public:
  24.     CPromptDlg(BOOL bEnabled, UINT nFlags, CWnd* pParent);
  25.  
  26.     //{{AFX_DATA(CPromptDlg)
  27.     enum { IDD = IDD_PROMPT };
  28.     BOOL    m_bEnabled;
  29.     BOOL    m_b0;
  30.     BOOL    m_b1;
  31.     BOOL    m_b2;
  32.     BOOL    m_b3;
  33.     BOOL    m_b4;
  34.     //}}AFX_DATA
  35.  
  36.     UINT CombineFlags();
  37.     virtual void DoDataExchange(CDataExchange* pDX);
  38.     //{{AFX_MSG(CPromptDlg)
  39.     //}}AFX_MSG
  40.     DECLARE_MESSAGE_MAP()
  41. };
  42.  
  43. BEGIN_MESSAGE_MAP(CPromptDlg, CDialog)
  44.     //{{AFX_MSG_MAP(CPromptDlg)
  45.     //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47.  
  48. CPromptDlg::CPromptDlg(BOOL bEnabled, UINT nFlags, CWnd* pParent)
  49.     : CDialog(CPromptDlg::IDD, pParent)
  50. {
  51.     //{{AFX_DATA_INIT(CPromptDlg)
  52.     m_bEnabled = bEnabled;
  53.     m_b0 = (nFlags & 1) != 0;
  54.     m_b1 = (nFlags & 2) != 0;
  55.     m_b2 = (nFlags & 4) != 0;
  56.     m_b3 = (nFlags & 8) != 0;
  57.     m_b4 = (nFlags & 0x10) != 0;
  58.     //}}AFX_DATA_INIT
  59. }
  60.  
  61. void CPromptDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63.     //{{AFX_DATA_MAP(CPromptDlg)
  64.     DDX_Check(pDX, IDC_ENABLEALL, m_bEnabled);
  65.     DDX_Check(pDX, IDC_BIT0, m_b0);
  66.     DDX_Check(pDX, IDC_BIT1, m_b1);
  67.     DDX_Check(pDX, IDC_BIT2, m_b2);
  68.     DDX_Check(pDX, IDC_BIT3, m_b3);
  69.     DDX_Check(pDX, IDC_BIT4, m_b4);
  70.     //}}AFX_DATA_MAP
  71. }
  72.  
  73. UINT CPromptDlg::CombineFlags()
  74. {
  75.     UINT nFlags = 0;
  76.     if (m_b0)
  77.         nFlags |= 1;
  78.     if (m_b1)
  79.         nFlags |= 2;
  80.     if (m_b2)
  81.         nFlags |= 4;
  82.     if (m_b3)
  83.         nFlags |= 8;
  84.     if (m_b4)
  85.         nFlags |= 0x10;
  86.     return nFlags;
  87. }
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // Public C interface
  91.  
  92. extern "C"
  93. BOOL FAR PASCAL EXPORT PromptTraceFlags(HWND hWndParent, TracerData FAR* lpData)
  94. {
  95.     TRACE0("Inside Trace DLL\n");
  96.  
  97.     // All DLL entry points should have a top-level TRY/CATCH block.
  98.     // Otherwise, it would be possible to throw an uncaught exception from
  99.     //  an the DLL.  This would most likely cause a crash.
  100.  
  101.     TRY
  102.     {
  103.         CPromptDlg dlg(lpData->bEnabled, lpData->flags,
  104.             CWnd::FromHandle(hWndParent));
  105.  
  106.         if (dlg.DoModal() != IDOK)
  107.             return FALSE;
  108.  
  109.         // update the data
  110.         lpData->bEnabled = dlg.m_bEnabled;
  111.         lpData->flags = dlg.CombineFlags();
  112.     }
  113.     CATCH_ALL(e)
  114.     {
  115.         // a failure caused an exception.
  116.         return FALSE;
  117.     }
  118.     END_CATCH_ALL
  119.  
  120.     return TRUE;
  121. }
  122.  
  123. /////////////////////////////////////////////////////////////////////////////
  124. // Library init
  125.  
  126. class CTracerDLL : public CWinApp
  127. {
  128. public:
  129.     virtual BOOL InitInstance(); // Initialization
  130.     virtual int ExitInstance();  // Termination (WEP-like code)
  131.  
  132.     // nothing special for the constructor
  133.     CTracerDLL(LPCTSTR pszAppName) : CWinApp(pszAppName) { }
  134. };
  135.  
  136. BOOL CTracerDLL::InitInstance()
  137. {
  138.     // any DLL initialization goes here
  139.     TRACE0("TRACE.DLL initializing\n");
  140.  
  141.     return TRUE;
  142. }
  143.  
  144. int CTracerDLL::ExitInstance()
  145. {
  146.     // any DLL termination goes here (WEP-like code)
  147.     return CWinApp::ExitInstance();
  148. }
  149.  
  150. extern "C" BOOL FAR PASCAL EXPORT FilterDllMsg(LPMSG lpMsg)
  151. {
  152.     TRY
  153.     {
  154.         return AfxGetApp()->PreTranslateMessage(lpMsg);
  155.     }
  156.     END_TRY
  157.     return FALSE;
  158. }
  159.  
  160. extern "C" void FAR PASCAL EXPORT ProcessDllIdle()
  161. {
  162.     TRY
  163.     {
  164.         // flush it all at once
  165.         long lCount = 0;
  166.         while (AfxGetApp()->OnIdle(lCount))
  167.             lCount++;
  168.     }
  169.     END_TRY
  170. }
  171.  
  172. CTracerDLL  NEAR tracerDLL(_T("trace.dll"));
  173.  
  174. /////////////////////////////////////////////////////////////////////////////
  175.