DECLARE_INTERFACE_(ISimpleCal, IUnknown)
{
STDMETHOD_(int, Sum)() PURE;
STDMETHOD_(int, Sub)() PURE;
};
DECLARE_INTERFACE_(IRadius, IUnknown)
{
STDMETHOD(Radius)(int x, int y, double* z) PURE;
};
#include "Interface.h"
class CSimpleCal2 : public CCmdTarget
{
...
// Attributes
public:
IUnknown* m_pAgrUnknown;
...
// Implementation
protected:
virtual BOOL OnCreateAggregates();
virtual ~CSimpleCal2();
BEGIN_INTERFACE_PART(CInnerSimpleCal2, IRadius)
STDMETHOD(Radius)(int x, int y, double* z);
END_INTERFACE_PART(CInnerSimpleCal2)
DECLARE_INTERFACE_MAP()
...
};
#include "SpcAgr1.h"
...
BEGIN_INTERFACE_MAP(CSimpleCal2, CCmdTarget)
INTERFACE_PART(CSimpleCal2, IID_IRadius, CInnerSimpleCal2)
INTERFACE_AGGREGATE(CSimpleCal2, m_pAgrUnknown)
END_INTERFACE_MAP()
CSimpleCal2::CSimpleCal2() : m_pAgrUnknown(NULL)
{
// {
EnableAggregation();
// }
AfxOleLockApp();
}
CSimpleCal2::~CSimpleCal2()
{
// {
if (m_pAgrUnknown)
{
m_pAgrUnknown->Release();
m_pAgrUnknown = NULL;
}
// }
AfxOleUnlockApp();
}
BOOL CSimpleCal2::OnCreateAggregates()
{
HRESULT hr;
hr = CoCreateInstance(SPC_COMPONENT,
GetControllingUnknown(),
CLSCTX_INPROC_SERVER,
IID_IUnknown,
(LPVOID*) &m_pAgrUnknown);
if(FAILED(hr))
{
// AfxMessageBox("내부 컴포넌트 생성에 실패");
return FALSE;
}
return TRUE;
}
...
STDMETHODIMP
CSimpleCal2::XCInnerSimpleCal2::Radius(int x, int y, double* z)
{
int x2, y2, z2;
HRESULT hr;
METHOD_PROLOGUE(CSimpleCal2, CInnerSimpleCal2)
ISimpleCal* pISc = NULL;
hr = pThis->m_pAgrUnknown->QueryInterface(IID_ISimpleCal, (void**)&pISc);
pISc->Sum();
*z = sqrt(z2);
// pThis->m_pAgrUnknown->Release(); ??
return S_OK;
}
DECLARE_INTERFACE_(ISimpleCal, IUnknown)
{
STDMETHOD_(int, Sum)() PURE;
STDMETHOD_(int, Sub)() PURE;
};
CSimpleCalc::CSimpleCalc()
{
// {
EnableAggregation();
// }
...
AfxOleLockApp();
}