import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(7059A459-EAA6-497E-9459-2AD61676A1AB),
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(59DC0533-88F3-4D5D-8937-9548B7CC023F),
version(1.0),
helpstring("SpcCnt 1.0 Type Library")
]
library SPCCNTLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(8CA2C642-DA69-48FA-BD87-802B3B9201A4),
helpstring("Radius Class")
]
coclass Radius
{
[default] interface IRadius;
};
};
#ifndef __RADIUS_H_
#define __RADIUS_H_
...
class ATL_NO_VTABLE CRadius :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CRadius, &CLSID_Radius>,
public IDispatchImpl<IRadius, &IID_IRadius, &LIBID_SPCCNTLib>
{
public:
...
// {
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,
NULL,
CLSCTX_ALL,
IID_ISimpleCalc,
(LPVOID*)&m_pSc);
if(FAILED(hr)) {
MessageBox(NULL, "Creation Failed", NULL, NULL);
}
return hr;
}
protected:
CComPtr<ISimpleCalc> m_pSc;
// }
// IRadius
public:
STDMETHOD(Radius)(/*[in]*/ int x, /*[in]*/ int y, /*[out, retval]*/ double *z);
};
#endif //__RADIUS_H_
#include "Radius.h"
#include <math.h>
STDMETHODIMP CRadius::Radius(int x, int y, double *z)
{
int zz1,zz2;
m_pSc->Mul(1,1,&zz1);
m_pSc->Mul(1,1,&zz2);
*z = sqrt(zz1 + zz2);
return S_OK;
}
import "oaidl.idl";
import "ocidl.idl";
[
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);
};