分类: C/C++
2008-08-01 17:07:47
STDMETHODIMP CCalCulate::Add(long n1, long n2, long *pVal) { // TODO: Add your implementation code here *pVal = n1 n2; return S_OK; }2.添加IFun2接口,继承IFun接口.步骤如下:
interface IFun : IUnknown { [helpstring("method Add")] HRESULT Add([in] long n1, [in] long n2, [out, retval] long *pVal); };下添加代码:
[ object, uuid(B9D75722-1950-405b-8BB6-9788A6DB1DB2), //是接口IFun2的标志数,可由VS的GUIDGEN.exe产生 helpstring("IFun2 Interface"), pointer_default(unique) ] interface IFun2 : IFun { };同时将末尾coclass CalCulate函数改为
coclass CalCulate { interface IFun; [default] interface IFun2; };(2) 修改CalCulate.h文件
class ATL_NO_VTABLE CCalCulate : public CComObjectRootEx改为, public CComCoClass , public IFun
class ATL_NO_VTABLE CCalCulate : public CComObjectRootEx在, public CComCoClass , public IFun2
BEGIN_COM_MAP(CCalCulate) COM_INTERFACE_ENTRY(IFun) END_COM_MAP()中添加
COM_INTERFACE_ENTRY(IFun2)(3) 在IFun2接口中添加Sub函数,方法同添加Add函数不再重复,只是实现时改为
*pVal = n1 - n2; // 返回两数差.(4) 编写客户端代码,调用IFun2接口的Add和Sub函数.