Echelon LNS User Manual

Page 345

Advertising
background image

LNS Programmer's Guide

331

Object Server and also advise for LNS Object Server events. This code is included in the
LNSMonitorCtrl.cpp file included with the LNS Turbo Edition examples suite.

HRESULT CLNSMonitorCtrlApp::OpenLca()

{

HRESULT hResult = S_OK;

hResult = m_pObjectServer.CreateInstance (_T("LonWorksObjectServer.1"));

if (hResult != S_OK)

{

// failed to create object server instance

m_IDS

=

IDS_FAILED_OBJSERVER;

return

hResult;

}

// Creating ObjectServer Event Handler...

m_pEventSink = new CEventSink();

if (m_pEventSink == NULL)

{

// failed to create event sink

m_IDS = IDS_FAILED_EVENT_HANDLER;

return

E_FAIL;

}

// Route the ObjectServer events to handlers in our EventSink class

hResult = m_pEventSink->DispEventAdvise(IUnknownPtr(m_pObjectServer));

return

hResult;

}

The CEventSink class is based on IDispEventSimpleImpl, and is used to handle LNS

Object Server events. This section briefly describes how the class was constructed. See
the EventSink.h file included with the LNS Turbo Edition example application suite

for complete source code, and reference the Microsoft Developer’s Network
documentation for more information on IDispEventSimpleImpl.

The event handler prototypes and the event handler information of type

ATL_FUNC_INFO for the SINK_ENTRY_INFO macros were created within the
EventSink.h file using the _com_dispatch_method calls:

#include "LNSMonitorCtrl.h"
static _ATL_FUNC_INFO OnNvMonitorPointEventInfo = {CC_STDCALL,
VT_EMPTY, 2,
{VT_DISPATCH, VT_I2}};
static _ATL_FUNC_INFO OnMsgMonitorPointEventInfo = {CC_STDCALL,
VT_EMPTY, 2,
{VT_DISPATCH, VT_I2}};

BEGIN_SINK_MAP(CEventSink)
SINK_ENTRY_INFO(IDC_EVENTS,
lca::DIID__DLcaObjectServerEvents,

Advertising