发表于:2007-07-17 18:50:00
13楼
我用OCPDA服务器与客户程序开发指南3.4节作了一遍,还不错,可再添加接口就报个C2259,C4259故障,好像多重接口配置的不对,哪位仁兄对ATL熟悉啊帮帮忙。
YDGROUP.h代码如下:
// YDGROUP.h : Declaration of the CYDGROUP
#ifndef __YDGROUP_H_
#define __YDGROUP_H_
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CYDGROUP
class ATL_NO_VTABLE CYDGROUP :
public CComObjectRootEx<CComSingleThreadModel>,
// public CComCoClass<CYDGROUP, &CLSID_YDGROUP>,
public IConnectionPointContainerImpl<CYDGROUP>,
// public IDispatchImpl<IYDGROUP, &IID_IYDGROUP, &LIBID_OPCDALib>,
// public IDispatchImpl<IOPCServer, &IID_IOPCServer, &LIBID_OPCDALib>,
public IOPCAsyncIO2,
public IOPCGroupStateMgt,
public IOPCItemMgt
// public IDispatchImpl<IOPCItemMgt, &IID_IOPCItemMgt, &LIBID_OPCDALib>,
// public IDispatchImpl<IOPCGroupStateMgt, &IID_IOPCGroupStateMgt, &LIBID_OPCDALib>,
// public IDispatchImpl<IOPCAsyncIO2, &IID_IOPCAsyncIO2, &LIBID_OPCDALib>
{
public:
CYDGROUP()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_YDGROUP)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CYDGROUP)
// COM_INTERFACE_ENTRY(IYDGROUP)
// COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
// COM_INTERFACE_ENTRY2(IDispatch,IOPCItemMgt)
COM_INTERFACE_ENTRY(IOPCAsyncIO2)
COM_INTERFACE_ENTRY(IOPCGroupStateMgt)
COM_INTERFACE_ENTRY(IOPCItemMgt)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(CYDGROUP)
END_CONNECTION_POINT_MAP()
// IYDGROUP
public:
// IOPCAsyncIO2
STDMETHOD (Read)(DWORD dwCount, OPCHANDLE * phServer, DWORD dwTransactionID, DWORD * pdwCancelID, HRESULT * * ppErrors)
{
if (pdwCancelID == NULL)
return E_POINTER;
if (ppErrors == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(Write)(DWORD dwCount, OPCHANDLE * phServer, VARIANT * pItemValues, DWORD dwTransactionID, DWORD * pdwCancelID, HRESULT * * ppErrors)
{
if (pdwCancelID == NULL)
return E_POINTER;
if (ppErrors == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(Refresh2)(OPCDATASOURCE dwSource, DWORD dwTransactionID, DWORD * pdwCancelID)
{
if (pdwCancelID == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(Cancel2)(DWORD dwCancelID)
{
return S_OK;
}
STDMETHOD(SetEnable)(BOOL bEnable)
{
return S_OK;
}
STDMETHOD(GetEnable)(BOOL * pbEnable)
{
if (pbEnable == NULL)
return E_POINTER;
return S_OK;
}
// IOPCGroupStateMgt
STDMETHOD(GetState)(DWORD * pUpdateRate, BOOL * pActive, LPWSTR * ppName, LONG * pTimeBias, FLOAT * pPercentDeadband, DWORD * pLCID, OPCHANDLE * phClientGroup, OPCHANDLE * phServerGroup)
{
if (pUpdateRate == NULL)
return E_POINTER;
if (pActive == NULL)
return E_POINTER;
if (ppName == NULL)
return E_POINTER;
if (pTimeBias == NULL)
return E_POINTER;
if (pPercentDeadband == NULL)
return E_POINTER;
if (pLCID == NULL)
return E_POINTER;
if (phClientGroup == NULL)
return E_POINTER;
if (phServerGroup == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(SetState)(DWORD * pRequestedUpdateRate, DWORD * pRevisedUpdateRate, BOOL * pActive, LONG * pTimeBias, FLOAT * pPercentDeadband, DWORD * pLCID, OPCHANDLE * phClientGroup)
{
if (pRevisedUpdateRate == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(SetName)(LPCWSTR szName)
{
return S_OK;
}
STDMETHOD(CloneGroup)(LPCWSTR szName, REFIID riid, LPUNKNOWN * ppUnk)
{
if (ppUnk == NULL)
return E_POINTER;
return S_OK;
}
// IOPCItemMgt
STDMETHOD(AddItems)(DWORD dwCount, OPCITEMDEF * pItemArray, OPCITEMRESULT * * ppAddResults, HRESULT * * ppErrors)
{
if (ppAddResults == NULL)
return E_POINTER;
if (ppErrors == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(ValidateItems)(DWORD dwCount, OPCITEMDEF * pItemArray, BOOL bBlobUpdate, OPCITEMRESULT * * ppValidationResults, HRESULT * * ppErrors)
{
if (ppValidationResults == NULL)
return E_POINTER;
if (ppErrors == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(RemoveItems)(DWORD dwCount, OPCHANDLE * phServer, HRESULT * * ppErrors)
{
if (ppErrors == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(SetActiveState)(DWORD dwCount, OPCHANDLE * phServer, BOOL bActive, HRESULT * * ppErrors)
{
if (ppErrors == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(SetClientHandles)(DWORD dwCount, OPCHANDLE * phServer, OPCHANDLE * phClient, HRESULT * * ppErrors)
{
if (ppErrors == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(SetDatatypes)(DWORD dwCount, OPCHANDLE * phServer, VARTYPE * pRequestedDatatypes, HRESULT * * ppErrors)
{
if (ppErrors == NULL)
return E_POINTER;
return S_OK;
}
STDMETHOD(CreateEnumerator)(REFIID riid, LPUNKNOWN * ppUnk)
{
if (ppUnk == NULL)
return E_POINTER;
return S_OK;
}
};
#endif //__YDGROUP_H_
故障代码如下:
OPCDA.cpp
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : error C2259: 'CComObject<class CYDServer>' : cannot instantiate abstract class due to following members:
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator<class ATL::CComObject<class CYDServer> >::CreateInstance(void *,const struct _GUID &,v
oid ** )'
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : warning C4259: 'long __stdcall IOPCServer::AddGroup(const unsigned short *,int,unsigned long,unsigned long,long *,float *,unsigned long,unsigned long *,unsigned long *,const
struct _GUID &,struct IUnknown ** )' : pure virtual function was not defined
j:\shoushutai\opcda\opcda.h(405) : see declaration of 'AddGroup'
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator<class ATL::CComObject<class CYDServer> >::CreateInstance(void *,const struct _GUID &,v
oid ** )'
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : error C2259: 'CComObject<class CYDServer>' : cannot instantiate abstract class due to following members:
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator<class ATL::CComObject<class CYDServer> >::CreateInstance(void *,const struct _GUID &,v
oid ** )'
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1827) : warning C4259: 'long __stdcall IOPCServer::AddGroup(const unsigned short *,int,unsigned long,unsigned long,long *,float *,unsigned long,unsigned long *,unsigned long *,const
struct _GUID &,struct IUnknown ** )' : pure virtual function was not defined
j:\shoushutai\opcda\opcda.h(405) : see declaration of 'AddGroup'
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(1823) : while compiling class-template member function 'long __stdcall ATL::CComCreator<class ATL::CComObject<class CYDServer> >::CreateInstance(void *,const struct _GUID &,v
oid ** )'
YDGROUP.cpp
YDServer.cpp
Generating Code...
Error executing cl.exe.
OPCDA.exe - 2 error(s), 2 warning(s)