调试程序的一种方法:

用了一下dbwin很方便。

下载的地方:  http://dilascia.com/TraceWin.htm

我用vc6, 所以下载 3.0

用的时候非常方便,在使用的文件前#include "TraceWin.h"

这样,后afxDump和Trace的字符串,都输入到TraceWin.exe这个程序中了。

调试ole, c/s的程序非常方便。

trwinshot.gif

后面附上源码:

ExpandedBlockStart.gif ContractedBlock.gif /**/ ////
None.gif //  TraceWin Copyright 1995-1999 Paul DiLascia
None.gif
//  If this program works, it was written by Paul DiLascia.
None.gif
//  If not, I don't know who wrote it.
None.gif
//
None.gif
//  NOTE: If you're using PixieLib, you don't need to include this file.
None.gif
//  It's already included by the library.
None.gif
//
None.gif
//  ***************************************************************************
None.gif
//  TraceWin is a tool that displays MFC diagnostic (afxDump, TRACE) output
None.gif
//  in the window of the TraceWin applet.
None.gif
//
None.gif
//  To use TraceWin, you must #include this file somewhere in your main program
None.gif
//  file (typically where you implement your CWinApp). Since this file contains
None.gif
//  code, you should #include it in only once--i.e. NOT in StdAfx.h--or you'll
None.gif
//  get multiply-defined symbol errors in the linker. This file contains an
None.gif
//  auto-initializing static variable that works in most cases; but you may miss
None.gif
//  some TRACE output from constructors of static objects. If so, you can
None.gif
//  manually call PxlTraceInit before your first TRACE call.
None.gif
//
None.gif
//  To see the output, you also need the TraceWin applet, TraceWin.exe, which
None.gif
//  you can download  http://pobox.com/ ~dilascia
None.gif
//
None.gif
//  ***************************************************************************
None.gif
//
None.gif
#ifdef _DEBUG
None.gif
None.gif
//  Window class name used by the main window of the TRACEWIN applet.
None.gif
#define  TRACEWND_CLASSNAME _T("TraceWin TRACE Window")
None.gif
#define  OLDTRACEWND_CLASSNAME _T("MfxTraceWindow")  //  backwards compat
None.gif
None.gif
//  ID sent as COPYDATASRUCT::dwData to identify the WM_COPYDATA message
None.gif
//  as coming from an app using TraceWin.
None.gif
#define  ID_COPYDATA_TRACEMSG MAKELONG(MAKEWORD('t','w'),MAKEWORD('i','n'))
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ //
None.gif //  CFileTrace is a CFile that "writes" to the trace window
None.gif
//
ExpandedBlockStart.gifContractedBlock.gif
class  CFileTrace :  public  CFile  dot.gif {
InBlock.gif    DECLARE_DYNAMIC(CFileTrace)
ExpandedSubBlockStart.gifContractedSubBlock.gif    CFileTrace() 
dot.gif{ m_strFileName = _T("Mfx File Tracer"); }
InBlock.gif    
static BOOL autoInit;
InBlock.gif    
virtual void Write(const void* lpBuf, UINT nCount);
InBlock.gif
public:
InBlock.gif    
static  BOOL Init();    
ExpandedBlockEnd.gif}
;
None.gifIMPLEMENT_DYNAMIC(CFileTrace, CFile)
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ //
None.gif //  Override to write to TraceWin applet instead of file.
None.gif
//
None.gif
void  CFileTrace::Write( const   void *  lpBuf, UINT nCount)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
if (!afxTraceEnabled)
InBlock.gif        
return;    // MFC tracing not enabled
InBlock.gif

InBlock.gif    HWND hTraceWnd 
= ::FindWindow(TRACEWND_CLASSNAME, NULL);
InBlock.gif    
if (hTraceWnd==NULL)
InBlock.gif        hTraceWnd 
= ::FindWindow(OLDTRACEWND_CLASSNAME, NULL);
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (hTraceWnd) dot.gif{
InBlock.gif        
// Found Trace window: send string with WM_COPYDATA
InBlock.gif        
// Must copy to make me the owner of the string; otherwise
InBlock.gif        
// barfs when called from MFC with traceMultiApp on
InBlock.gif        
//
InBlock.gif
        static char mybuf[1024];
InBlock.gif
InBlock.gif#ifdef _UNICODE
InBlock.gif        BOOL bDefCharUsed;
InBlock.gif        ::WideCharToMultiByte(CP_ACP,
0,LPCWSTR(lpBuf),
InBlock.gif            
-1, mybuf, 1024, NULL, &bDefCharUsed);
InBlock.gif
#else
InBlock.gif        memcpy(mybuf, lpBuf, nCount);
InBlock.gif
#endif
InBlock.gif
InBlock.gif        COPYDATASTRUCT cds;
InBlock.gif        cds.dwData 
= ID_COPYDATA_TRACEMSG;
InBlock.gif        cds.cbData 
= nCount;
InBlock.gif        cds.lpData 
= mybuf;
InBlock.gif        CWinApp
* pApp = AfxGetApp();
InBlock.gif        HWND hWnd 
= pApp ? pApp->m_pMainWnd->GetSafeHwnd() : NULL;
InBlock.gif        ::SendMessage(hTraceWnd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)
&cds);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
// Also do normal debug thing
InBlock.gif
    ::OutputDebugString((LPCTSTR)lpBuf);
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ /////
None.gif //  Initialize tracing. Replace global afxDump.m_pFile with CFileTrace object.
None.gif
//  In VC 5.0, you shouldn't need to call this, since it's called from an
None.gif
//  auto-initializing static object autoInit below. But if you don't see
None.gif
//  any TRACE output in the TraceWin window, you should try calling
None.gif
//  PxlTraceInit any time before your first TRACE message.
None.gif
//
None.gif
BOOL CFileTrace::Init()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if (afxDump.m_pFile==NULL) dot.gif{
InBlock.gif        
// Initialize tracing: replace afxDump.m_pFile w/my own CFile object
InBlock.gif        
//
InBlock.gif        
// It's important to allocate with "new" here, not a static object,
InBlock.gif        
// because CFileTrace is virtual--i.e., called through a pointer in
InBlock.gif        
// the object's vtbl--and the compiler will zero out the virtual
InBlock.gif        
// function table with a NOP function when a static object
InBlock.gif        
// goes out of scope. But I want my CFileTrace to stay around to
InBlock.gif        
// display memory leak diagnostics even after all static objects
InBlock.gif        
// have been destructed. So I allocate the object with new and
InBlock.gif        
// never delete it. I don't want this allocation to itself generate
InBlock.gif        
// a reported memory leak, so I turn off memory tracking before I
InBlock.gif        
// allocate, then on again after.
InBlock.gif        
//
InBlock.gif
        BOOL bEnable = AfxEnableMemoryTracking(FALSE);
InBlock.gif        afxDump.m_pFile 
= new CFileTrace;
InBlock.gif        AfxEnableMemoryTracking(bEnable);
InBlock.gif        
return TRUE;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return FALSE;
ExpandedBlockEnd.gif}

None.gif
ExpandedBlockStart.gifContractedBlock.gif
/**/ //
None.gif //  This object does nothing but call CFileTrace::Init, so all you have to
None.gif
//  do is #include this file. Because afxDump is defined in a module with
None.gif
//
None.gif
//  #pragma init_seg(lib)
None.gif
//
None.gif
//  afxDump gets initialized before the "user" segment which is where your
None.gif
//  app (and autoInit) is by default. If you need to use init_seg(lib),
None.gif
//  or you have other objects whose constructors call TRACE that get
None.gif
//  initialized before CFileTrace::bInitialized, you will have to call
None.gif
//  CFileTrace::Init yourself, before your first TRACE statement.
None.gif
//
None.gif
BOOL CFileTrace::autoInit  =  CFileTrace::Init();
None.gif
None.gif
//  This symbol defined so you can call it and have it
None.gif
//  compile to nothing in non-debug build
None.gif
#define  PxlTraceInit() CFileTrace::Init();
None.gif
None.gif
#else
None.gif
None.gif
#define  PxlTraceInit()
None.gif
None.gif
#endif   //  _DEBUG
None.gif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值