📄 slikserverevents.cpp
字号:
// SLIKServerEvents.cpp: implementation of the CSLIKServerEvents class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SLIKServerEvents.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSLIKServerEvents::CSLIKServerEvents()
{
}
CSLIKServerEvents::~CSLIKServerEvents()
{
}
//////////////////////////////////////////////////////////////////////
// Event Handlers
//////////////////////////////////////////////////////////////////////
HRESULT __stdcall CSLIKServerEvents::OnClientConnectHandler(
long lNumClients,
VARIANT_BOOL *pbAcceptConnection
)
{
//
// We'll accept any connection that DCOM security accepts
//
*pbAcceptConnection = VARIANT_TRUE;
return S_OK;
}
HRESULT __stdcall CSLIKServerEvents::OnClientDisconnectHandler(
long lNumClients
)
{
//
// We can shut down if there are no longer any connected clients
//
if( lNumClients == 0 )
PostThreadMessage( GetCurrentThreadId(), WM_QUIT, 0, 0 );
return S_OK;
}
HRESULT __stdcall CSLIKServerEvents::OnReadHandler(
long lCount,
SAFEARRAY **ppsaTags, // ptr to safe array of ISLIKTag *
SAFEARRAY **ppsaAccessPaths, // ptr to safe array of BSTR
SAFEARRAY **ppsaErrors, // ptr to safe array of long
long *plResult
)
{
HRESULT hr = S_OK;
try
{
*plResult = S_OK;
//
// In this implementation, we assume that the data simulation
// already has provided the most up to date data. So, we just
// update the output parameters, as required.
//
// NOTE: All safe arrays from SLIK-DA events are 0-based
//
for( long i = 0; i < lCount; i++ )
{
long lError = S_OK;
_com_util::CheckError( SafeArrayPutElement( *ppsaErrors, &i, &lError ) );
}
*plResult = S_OK;
}
catch( _com_error e )
{
hr = e.Error();
}
return hr;
}
HRESULT __stdcall CSLIKServerEvents::OnWriteHandler(
long lCount,
SAFEARRAY **ppsaTags, // ptr to safe array of ISLIKTag *
SAFEARRAY **ppsaAccessPaths, // ptr to safe array of BSTR
SAFEARRAY **ppsaValues, // ptr to safe array of VARIANT
SAFEARRAY **ppsaErrors, // ptr to safe array of long
long *plResult
)
{
HRESULT hr = S_OK;
try
{
*plResult = S_OK;
//
// This SIMPLE implementation just copies the given value to the
// corresponding tag. A REAL implementation would typically be
// more rigorous here with respect to range checking, etc.
//
// NOTE: All safe arrays from SLIK-DA events are 0-based
//
for( long i = 0; i < lCount; i++ )
{
VARIANT vVal;
_com_util::CheckError( SafeArrayGetElement( *ppsaValues, &i, &vVal ) );
CComPtr<ISLIKTag> spTag;
_com_util::CheckError( SafeArrayGetElement( *ppsaTags, &i, &spTag ) );
long lError = spTag->SetVQT( vVal, sdaGood, 0 );
_com_util::CheckError( SafeArrayPutElement( *ppsaErrors, &i, &lError ) );
if( FAILED( lError ) )
*plResult = S_FALSE;
}
}
catch( _com_error e )
{
hr = e.Error();
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -