// start generated code BOOL CTest2App::InitInstance() { // Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } AfxEnableControlContainer(); if (RunEmbedded() || RunAutomated()) { // Register all OLE server (factories) as running. This enables the // OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll(); } else { // When a server application is launched stand-alone, it is a good idea // to update the system registry in case it has been damaged. COleObjectFactory::UpdateRegistryAll(); } CTest2Dlg dlg; m_pMainWnd = &dlg; // end generated code cstDataServer oDataServer; COleException *pError = new COleException; oDataServer.CreateDispatch( "dataserver2.cstdataserver", pError ); oDataServer.Initialize(); //... calls to server in here work fine oDataServer.Terminate(); oDataServer.ReleaseDispatch(); int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } return FALSE; }