// Create the event sink object.
CComObject<CEventHandler> *pHandler;
CComObject<CEventHandler>::CreateInstance(&pHandler);
// Advise the connection point object of the client's sink.
rc = AtlAdvise(m_pObj2, pHandler->GetUnknown(),
IID_IObj2Events, &m_Cookie);
if (FAILED(rc))
MessageBox("Failure to connect sink.");
还有以下的:
BOOL CTestUtilApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
_Module.Init(NULL, NULL);
AfxOleInit();
CTestUtilDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
_Module.Term();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}