例如,我选对话框类型的应用程序。为什么多了一个 DialogxxxxxAutoProxy. 这个AutoProxy和我的CDilaog对象之间,存在依赖关系么?
或者说,这个所谓的Proxy对象,是为谁做"代理",因为我看CDialog的构造/析构函数里面都涌到了它。
这个类看起来还挺复杂的。我把VC6自动生成的代码贴到这里:class CDialog007DlgAutoProxy : public CCmdTarget
{
DECLARE_DYNCREATE(CDialog007DlgAutoProxy) CDialog007DlgAutoProxy();           // protected constructor used by dynamic creation// Attributes
public:
CDialog007Dlg* m_pDialog;// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDialog007DlgAutoProxy)
public:
virtual void OnFinalRelease();
//}}AFX_VIRTUAL// Implementation
protected:
virtual ~CDialog007DlgAutoProxy(); // Generated message map functions
//{{AFX_MSG(CDialog007DlgAutoProxy)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG DECLARE_MESSAGE_MAP()
DECLARE_OLECREATE(CDialog007DlgAutoProxy) // Generated OLE dispatch map functions
//{{AFX_DISPATCH(CDialog007DlgAutoProxy)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
};
.cpp:
IMPLEMENT_DYNCREATE(CDialog007DlgAutoProxy, CCmdTarget)CDialog007DlgAutoProxy::CDialog007DlgAutoProxy()
{
EnableAutomation();

// To keep the application running as long as an automation 
// object is active, the constructor calls AfxOleLockApp.
AfxOleLockApp(); ASSERT (AfxGetApp()->m_pMainWnd != NULL);
ASSERT_VALID (AfxGetApp()->m_pMainWnd);
ASSERT_KINDOF(CDialog007Dlg, AfxGetApp()->m_pMainWnd);
m_pDialog = (CDialog007Dlg*) AfxGetApp()->m_pMainWnd;
m_pDialog->m_pAutoProxy = this;
}CDialog007DlgAutoProxy::~CDialog007DlgAutoProxy()
{
if (m_pDialog != NULL)
m_pDialog->m_pAutoProxy = NULL;
AfxOleUnlockApp();
}void CDialog007DlgAutoProxy::OnFinalRelease()
{
CCmdTarget::OnFinalRelease();
}BEGIN_MESSAGE_MAP(CDialog007DlgAutoProxy, CCmdTarget)
//{{AFX_MSG_MAP(CDialog007DlgAutoProxy)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()BEGIN_DISPATCH_MAP(CDialog007DlgAutoProxy, CCmdTarget)
//{{AFX_DISPATCH_MAP(CDialog007DlgAutoProxy)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()// Note: we add support for IID_IDialog007 to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.// {44C684A9-8086-4531-BF24-D6CF3C022FE6}
static const IID IID_IDialog007 =
{ 0x44c684a9, 0x8086, 0x4531, { 0xbf, 0x24, 0xd6, 0xcf, 0x3c, 0x2, 0x2f, 0xe6 } };BEGIN_INTERFACE_MAP(CDialog007DlgAutoProxy, CCmdTarget)
INTERFACE_PART(CDialog007DlgAutoProxy, IID_IDialog007, Dispatch)
END_INTERFACE_MAP()// {7E19B087-0F97-4925-A9C8-6BC959C37D26}
IMPLEMENT_OLECREATE2(CDialog007DlgAutoProxy, "Dialog007.Application", 0x7e19b087, 0xf97, 0x4925, 0xa9, 0xc8, 0x6b, 0xc9, 0x59, 0xc3, 0x7d, 0x26)class CDialog007Dlg : public CDialog
{
DECLARE_DYNAMIC(CDialog007Dlg);
friend class CDialog007DlgAutoProxy;
protected:
CDialog007DlgAutoProxy* m_pAutoProxy;
CDialog007Dlg::CDialog007Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CDialog007Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialog007Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pAutoProxy = NULL;
}CDialog007Dlg::~CDialog007Dlg()
{
if (m_pAutoProxy != NULL)
m_pAutoProxy->m_pDialog = NULL;
}15. 
void CDialog007Dlg::OnCancel() 
{
if (CanExit())
CDialog::OnCancel();
}BOOL CDialog007Dlg::CanExit()
{
if (m_pAutoProxy != NULL)
{
ShowWindow(SW_HIDE);
return FALSE;
} return TRUE;
}