【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“ConnectionPoint.cpp”一文,供大家参考学习
//**************************************************************************
//
// Description: Callback class for OPC Data Access 2.0
//
//**************************************************************************
#include "stdafx.h"
#include "OPCClientSpy.h"
#include "ConnectionPoint.h"
#include "IAdvSink.hpp"
#include "ValueMsgView.h"
extern CValueMsgView *theMsgValue;
CComModule _Module; // just needed to keep ATL happy
//**************************************************************************
// Called by the server at the update rate when data changes
STDMETHODIMP OPCCallback::OnDataChange(
DWORD Transid,
OPCHANDLE grphandle,
HRESULT masterquality,
HRESULT mastererror,
DWORD count,
OPCHANDLE * clienthandles,
VARIANT * values,
WORD * quality,
FILETIME * time,
HRESULT * errors)
{
// If Transid != 0, this is a refresh
for( DWORD index=0; index<count; index++ )
{
if( SUCCEEDED(errors[index]) )
{
Item* pItem = (Item*)clienthandles[index];
if( pItem )
{
pItem->value = values[index];
pItem->quality = quality[index];
pItem->timestamp = time[index];
}
}
}
PostMessage(*theMsgValue, WM_OPCDATA, 0, 0);
return S_OK;
}
//**************************************************************************
// Called by the server to complete an ASyncIO2::Read
STDMETHODIMP OPCCallback::OnReadComplete(
DWORD Transid,
OPCHANDLE grphandle,
HRESULT masterquality,
HRESULT mastererror,
DWORD count,
OPCHANDLE * clienthandles,
VARIANT * values,
WORD * quality,
FILETIME * time,
HRESULT * errors)
{
ASSERT( Transid == 3 ); // test only
for( DWORD index=0; index<count; index++ )
{
if( SUCCEEDED(errors[index]) )
{
Item* pItem = (Item*)clienthandles[index];
if( pItem )
{
pItem->value = values[index];
pItem->quality = quality[index];
pItem->timestamp = time[index];
}
}
}
PostMessage(*theMsgValue, WM_OPCDATA, 0, 0);
return S_OK;
}
//**************************************************************************
// Called by the server to complete an ASyncIO2::Write
STDMETHODIMP OPCCallback::OnWriteComplete(
DWORD Transid,
OPCHANDLE grphandle,
HRESULT mastererr,
DWORD count,
OPCHANDLE * clienthandles,
HRESULT * errors)
{
ASSERT( Transid == 2 ); // test only
for( DWORD index=0; index<count; index++ )
{
if( FAILED(errors[index]) )
{
Item* pItem = (Item*)clienthandles[index];
PostMessage(*theMsgValue, WM_OPCWRITE, errors[index], 0);
}
}
return S_OK;
}
//**************************************************************************
// Called by the server to complete an ASyncIO2::Cancel
STDMETHODIMP OPCCallback::OnCancelComplete(
DWORD transid,
OPCHANDLE grphandle)
{
return S_OK;
}
//**************************************************************************
// Called by 2.0 servers when shutting down.
STDMETHODIMP OPCShutdown::ShutdownRequest(LPCWSTR szReason)
{
reason = szReason;
PostMessage(*theMsgValue, WM_OPCSHUTDOWN, (WPARAM)reason.GetBuffer(0), 0);
return S_OK;
}
上一篇:
ConnectionDlg.cpp
下一篇:
电脑辐射可致十九种疾病