1. AppWizard로 SDI 프로젝트를 생성한다. 이 때 스텝3에서 [Automation]을 체크한다.
2. ClassView에서 인터페이스를 선택해서 팝업메뉴에서 [Add Method]/[Add Property]를 사용해서 메소드와 프라퍼티를 추가한다.
/*
or
ClassWizard's Automation page
Add Method button
Add Property button
*/
modifications to the project's source code files:
The method and its dispatch ID are added to the project's ODL file.
The function that implements the method is declared in the class's header file.
An empty function implementation is added to the class's CPP file.
A DISP_FUNCTION statement is added to the class's dispatch map.
two types of Automation properties
Member variable properties
DISP_PROPERTY()
DISP_PROPERTY_NOTIFY()
Get/set properties
DISP_PROPERTY_EX()
DISP_PROPERTY_PARAM()
indexed properties
// MiniGraph.odl : type library source for MiniGraph.exe
// This file will be processed by the MIDL compiler to produce the // type library (MiniGraph.tlb).
// Primary dispatch interface for CMiniGraphDoc [ uuid(773FFCD7-01D5-4EA5-BC0B-0EF01724819F) ] dispinterface IMiniGraph { properties: // NOTE - ClassWizard will maintain property information here. // Use extreme caution when editing this section. //{{AFX_ODL_PROP(CMiniGraphDoc) [id(1)] BSTR AutoText;
[id(2)] long X;
[id(3)] long Y;
//}}AFX_ODL_PROP methods: // NOTE - ClassWizard will maintain method information here. // Use extreme caution when editing this section. //{{AFX_ODL_METHOD(CMiniGraphDoc) [id(4)] void ShowApplication(); //}}AFX_ODL_METHOD
};
// Class information for CMiniGraphDoc [ uuid(E93CCCBD-11AB-4DAE-8501-AA67AD416A8D) ] coclass Document { [default] dispinterface IMiniGraph; };
class CTextServerApp : public CWinApp
{
...
// Implementation COleTemplateServer m_server;
// Server object for document creation
//{{AFX_MSG(CTextServerApp)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// The one and only CMiniGraphApp object
CMiniGraphApp theApp;
// {
// This identifier was generated to be statistically unique for your app.
// You may change it if you prefer to choose a specific identifier.
BOOL CMiniGraphApp::InitInstance()
{
// Initialize OLE libraries if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; }
AfxEnableControlContainer();
...
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CTextServerDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CTextServerView));
AddDocTemplate(pDocTemplate);
// Connect the COleTemplateServer to the document template.
// The COleTemplateServer creates new documents on behalf
// of requesting OLE containers by using information
// specified in the document template. m_server.ConnectTemplate(clsid, pDocTemplate, TRUE);
// Note: SDI applications register server objects only if /Embedding
// or /Automation is present on the command line.
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// {
// Check to see if launched as OLE server if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) { // Register all OLE server (factories) as running. This enables the
// OLE libraries to create objects from other applications. COleTemplateServer::RegisterAll();
// Application was run with /Embedding or /Automation. Don't show the
// main window in this case. return TRUE; }
// When a server application is launched stand-alone, it is a good idea
// to update the system registry in case it has been damaged. m_server.UpdateRegistry(OAT_DISPATCH_OBJECT); COleObjectFactory::UpdateRegistryAll();
// }
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
...
}
class CMiniGraphDoc : public CDocument
{
...
// Implementation
public: int m_nX; int m_nY; CString m_strText;
virtual ~CTextServerDoc();
...
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CMiniGraphDoc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// {
// Generated OLE dispatch map functions
//{{AFX_DISPATCH(CMiniGraphDoc) CString m_autoText; afx_msg void OnAutoTextChanged(); afx_msg long GetX(); afx_msg void SetX(long nNewValue); afx_msg long GetY(); afx_msg void SetY(long nNewValue); afx_msg void ShowApplication(); //}}AFX_DISPATCH DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP()
// }
};
// Note: we add support for IID_IMiniGraph to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
CMiniGraphDoc::CMiniGraphDoc()
{
// TODO: add one-time construction code here
// {
m_pGraph = new CGraph();
ASSERT(m_pGraph);
// Test only - give it some data to use, while we're developing
m_pGraph->SetTitle("First Graph");
m_pGraph->AddData("A", 20);
// } EnableAutomation(); AfxOleLockApp();
}
CMiniGraphDoc::~CMiniGraphDoc()
{ AfxOleUnlockApp();
}
... void CMiniGraphDoc::ShowApplication() { // TODO: Add your dispatch handler code here CMiniGraphApp* pApp = (CMiniGraphApp*) AfxGetApp(); CMainFrame* pFrame = (CMainFrame*) pApp->m_pMainWnd;
void CClockServerDoc::OnFinalRelease() { // TODO: Add your specialized code here and/or call the base class // { ::RevokeActiveObject(m_dwID, NULL); // } CDocument::OnFinalRelease(); }