ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • ATL로 Aggregation 구현하기
    컴포넌트(COM)/Aggregation 2008. 11. 27. 00:09
        [
            object,
            uuid(0672F710-52C8-4B5E-8942-61C354AAB91A),
            dual,
            helpstring("IRadius Interface"),
            pointer_default(unique)
        ]
        interface IRadius : IDispatch
        {
            [id(1), helpstring("method Radius")] HRESULT Radius([in] int x, [in] int y, [out, retval] double *z);
        };

        [
            object,
            uuid(1F37A7CC-582F-4A1D-9316-AE95F03E6860),
            dual,
            helpstring("ISimpleCalc Interface"),
            pointer_default(unique)
        ]
        interface ISimpleCalc : IDispatch
        {
            [id(1), helpstring("method Sum")] HRESULT Sum([in] int x, [in] int y, [out, retval] int *z);
            [id(2), helpstring("method Sub")] HRESULT Sub([in] int x, [in] int y, [out, retval] int *z);
            [id(3), helpstring("method Mul")] HRESULT Mul([in] int x, [in] int y, [out, retval] int *z);
            [id(4), helpstring("method Div")] HRESULT Div([in] int x, [in] int y, [out, retval] double *z);
        };

    [
        uuid(94F24141-08A7-448A-BCF4-B84D5239541A),
        version(1.0),
        helpstring("SpcAgr 1.0 Type Library")
    ]
    library SPCAGRLib
    {
        [
            uuid(3BA1DC6D-889C-4D7C-BA6B-CA663E7186F3),
            helpstring("Radius Class")
        ]
        coclass Radius
        {
            [default] interface IRadius;
            interface ISimpleCalc;
        };
    };

    #ifndef __RADIUS_H_
    #define __RADIUS_H_
    ...
    class ATL_NO_VTABLE CRadius :
        ...
        public IDispatchImpl<IRadius, &IID_IRadius, &LIBID_SPCAGRLib>
    {
    public:
    ...
    BEGIN_COM_MAP(CRadius)
        COM_INTERFACE_ENTRY(IRadius)
        COM_INTERFACE_ENTRY(IDispatch)
        COM_INTERFACE_ENTRY_AGGREGATE(IID_ISimpleCalc, m_pUnk.p)
    END_COM_MAP()
    // {
    DECLARE_GET_CONTROLLING_UNKNOWN()

        HRESULT FinalConstruct()
        {
            HRESULT hr;
            CLSID clsid;

            hr = ::CLSIDFromProgID(OLESTR("SpcCom.SimpleCalc.1"), &clsid);
            if(FAILED(hr)) {
                MessageBox(NULL, "Can't get CLSID", NULL, NULL);
                return hr;
            }

            hr = ::CoCreateInstance(
                    clsid,
                    GetControllingUnknown(),
                    CLSCTX_ALL,
                    IID_IUnknown,
                    (LPVOID*)&m_pUnk);
            if(FAILED(hr)) {
    //            MessageBox(NULL, "객체 생성 실패", NULL, NULL);
                return hr;
            }

            return hr;
        }

    protected:       
        CComPtr<IUnknown> m_pUnk;
    // }
    // IRadius
    public:
        STDMETHOD(Radius)(/*[in]*/ int x, /*[in]*/ int y, /*[out, retval]*/ double *z);
    };

    #endif //__RADIUS_H_

        [
            object,
            uuid(1F37A7CC-582F-4A1D-9316-AE95F03E6860),
            dual,
            helpstring("ISimpleCalc Interface"),
            pointer_default(unique)
        ]
        interface ISimpleCalc : IDispatch
        {
            [id(1), helpstring("method Sum")] HRESULT Sum([in] int x, [in] int y, [out, retval] int *z);
            [id(2), helpstring("method Sub")] HRESULT Sub([in] int x, [in] int y, [out, retval] int *z);
            [id(3), helpstring("method Mul")] HRESULT Mul([in] int x, [in] int y, [out, retval] int *z);
            [id(4), helpstring("method Div")] HRESULT Div([in] int x, [in] int y, [out, retval] double *z);
        };

Designed by Tistory.