; SpcCom.def : Declares the module parameters for the DLL.
LIBRARY "SpcCom"
DESCRIPTION 'SpcCom Windows Dynamic Link Library'
EXPORTS
; Explicit exports can go here
DllCanUnloadNow @1 PRIVATE
DllGetClassObject @2 PRIVATE
DllRegisterServer @3 PRIVATE
DllUnregisterServer @4 PRIVATE
CLSID_STR_CLASSID 는 스트링 리소스이다.
#include <afxctl.h>
BOOL CSpcComApp::InitInstance()
{
// TODO: Add your specialized code here and/or call the base class
// {
AfxOleLockApp();
return COleObjectFactory::RegisterAll();
// }
// return CWinApp::InitInstance();
}
int CSpcComApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
// {
AfxOleUnlockApp();
return 0;
// }
// return CWinApp::ExitInstance();
}
STDAPI DllRegisterServer()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
COleObjectFactory::UpdateRegistryAll();
return S_OK;
}
STDAPI DllUnregisterServer()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// Load up various strings from the resource stringtable
CString strClassID;
strClassID.LoadString(CLSID_STR_CLASSID);
CLSID CLSID_COMPONENT;
BSTR bstrClassID = strClassID.AllocSysString();
CLSIDFromString(bstrClassID, &CLSID_COMPONENT);
SysFreeString(bstrClassID);
// Unregister the class
return AfxOleUnregisterClass(CLSID_COMPONENT, "SPC_COMPONENT");
}
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return AfxDllGetClassObject(rclsid, riid, ppv);
// or return CClassFactory::GetClassObject(rclsid, riid, ppv);
}
STDAPI DllCanUnloadNow()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return AfxDllCanUnloadNow();
// or return CClassFactory::CanUnloadNow()
}
//////////////////////////////////////////////////////////////
DECLARE_INTERFACE_(ISetValue, IUnknown)
{
STDMETHOD_(void, SetValue)(int x1, int y1) PURE;
};
DECLARE_INTERFACE_(ISimpleCal, IUnknown)
{
STDMETHOD_(int, Sum)() PURE;
STDMETHOD_(int, Sub)() PURE;
}
#ifndef SIMPLECALC_H
#define SIMPLECALC_H
#include "interface.h"
class CSimpleCalc : public CCmdTarget
{
public:
// Constructor
CSimpleCalc();
// Destructor
virtual ~CSimpleCalc();
protected:
BEGIN_INTERFACE_PART(CInnerSetValue, ISetValue)
STDMETHOD_(void, SetValue)(int x1, int y1);
END_INTERFACE_PART(CInnerSetValue)
BEGIN_INTERFACE_PART(CInnerSimpleCal, ISimpleCal)
STDMETHOD_(int, Sum)();
STDMETHOD_(int, Sub)();
END_INTERFACE_PART(CInnerSimpleCal)
DECLARE_INTERFACE_MAP()
DECLARE_OLECREATE(CSimpleCalc)
DECLARE_DYNCREATE(CSimpleCalc)
};
typedef CSimpleCalc* PSimpleCalc;
#endif
#include "stdafx.h"
#include "spccom1.h"
#include "guids.h"
// Support dynamic creation
IMPLEMENT_DYNCREATE(CSimpleCalc, CCmdTarget)
// {6095B7B8-D683-411f-B015-5AB1845B70D6}
IMPLEMENT_OLECREATE(CSimpleCalc, "SPC_COMPONENT",
0x6095b7b8, 0xd683, 0x411f, 0xb0, 0x15, 0x5a, 0xb1, 0x84, 0x5b, 0x70, 0xd6);
BEGIN_INTERFACE_MAP(CSimpleCalc, CCmdTarget)
INTERFACE_PART(CSimpleCalc, IID_ISetValue, CInnerSetValue)
INTERFACE_PART(CSimpleCalc, IID_ISimpleCal, CInnerSimpleCal)
END_INTERFACE_MAP()
static int x;
static int y;
CSimpleCalc::CSimpleCalc()
{
AfxOleLockApp();
}
CSimpleCalc::~CSimpleCalc()
{
AfxOleUnlockApp();
}
STDMETHODIMP_(ULONG)
CSimpleCalc::XCInnerSetValue::AddRef()
{
METHOD_PROLOGUE(CSimpleCalc, CInnerSetValue)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG)
CSimpleCalc::XCInnerSetValue::Release()
{
METHOD_PROLOGUE(CSimpleCalc, CInnerSetValue)
return pThis->ExternalRelease();
}
STDMETHODIMP
CSimpleCalc::XCInnerSetValue::QueryInterface(REFIID riid, LPVOID* ppv)
{
METHOD_PROLOGUE(CSimpleCalc, CInnerSetValue)
return pThis->ExternalQueryInterface(&riid, ppv);
}
STDMETHODIMP_(void)
CSimpleCalc::XCInnerSetValue::SetValue(int x1,int y1)
{
x = x1;
y = y1;
}
// ISimpleCal
STDMETHODIMP_(ULONG)
CSimpleCalc::XCInnerSimpleCal::AddRef()
{
METHOD_PROLOGUE(CSimpleCalc, CInnerSimpleCal)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG)
CSimpleCalc::XCInnerSimpleCal::Release()
{
METHOD_PROLOGUE(CSimpleCalc, CInnerSimpleCal)
return pThis->ExternalRelease();
}
STDMETHODIMP
CSimpleCalc::XCInnerSimpleCal::QueryInterface(REFIID riid, LPVOID* ppv)
{
METHOD_PROLOGUE(CSimpleCalc, CInnerSimpleCal)
return pThis->ExternalQueryInterface(&riid, ppv);
}
STDMETHODIMP_(int)
CSimpleCalc::XCInnerSimpleCal::Sum()
{
return x + y;
}
STDMETHODIMP_(int)
CSimpleCalc::XCInnerSimpleCal::Sub()
{
return x - y;
}