Anonymous Anonymous - 1 year ago
219 0

No description

C++

uforte generated code from the wizard

// OPCClient_VC_6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#import "..\..\ufOPCClientToolkit.dll"

class Callback : public ufOPCClientToolkitLib::IufCallback
{
    HRESULT __stdcall raw_OnNewData(
        /* [in] */ BSTR bstrItemID,
        /* [in] */ VARIANT vValue,
        /* [in] */ DATE dTime,
        /* [in] */ LONG wQuality)
	{
		printf("Values were retrieved asynchronously!\n");

		return S_OK;
	}

	HRESULT STDMETHODCALLTYPE QueryInterface( REFIID iid, LPVOID* ppInterface)
	{
		if ( ppInterface == NULL)	return E_INVALIDARG;

		*ppInterface = NULL;

		if ( iid == IID_IUnknown )
		{
			*ppInterface = dynamic_cast<IUnknown *>(this);
		}   
		else if ( iid == __uuidof (ufOPCClientToolkitLib::IufCallback))
		{
			*ppInterface = dynamic_cast<ufOPCClientToolkitLib::IufCallback*>(this);
		}
		else
		{
			return E_NOINTERFACE;
		}

		AddRef ();

		return S_OK;
	}

	ULONG STDMETHODCALLTYPE AddRef( void)	{ return 2;	}

	ULONG STDMETHODCALLTYPE Release( void) { return 1; }
};

int main(int argc, char* argv[])
{
	HRESULT hr;

	hr = CoInitializeEx (NULL, COINIT_MULTITHREADED);

	CLSID clsid;
	Callback callback;

	hr = CLSIDFromProgID (L"ufOPCClientToolkit.ufOPCClientHelper", &clsid);

	ufOPCClientToolkitLib::IufOPCClientHelper *pHelper;

	hr = CoCreateInstance (clsid, NULL, CLSCTX_ALL, __uuidof(ufOPCClientToolkitLib::IufOPCClientHelper)
		, (LPVOID*) &pHelper);

	hr = pHelper->raw_Connect(_bstr_t(L"uForte.ufOPCDASrvCust"), 2, _bstr_t(L""));

	hr = pHelper->raw_SetCallback (&callback);

	hr = pHelper->raw_StartReadingItem (_bstr_t(L"Test.ReadWrite.BOOL"));

	while (true)
	{
		// retrieve data synchronously
		VARIANT vValue;
		DATE dtTime;
		LONG usQuality;

		hr = pHelper->raw_GetItemValue(_bstr_t(L"Test.ReadWrite.BOOL"), &vValue, &dtTime, &usQuality);

		printf("Values were retrieved synchronously!\n");

		Sleep (1000);
	}

	hr = pHelper->raw_Disconnect ();

	return 0;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download