beautypg.com

Early and late binding – Teledyne LeCroy WaveExpert series Automation Manual User Manual

Page 34

background image

A

BOUT

A

UTOMATION

1-22

916435 RevA

EARLY AND LATE BINDING

The COM standard on which Automation is built supports two kinds of “binding” between client and server: early

(static), and late (dynamic, dispatch). Static binding usually involves a type library and is used primarily by

compiled languages such as C++. In this case, function entry points are resolved at compile time. Dynamic

binding (also known as late binding) involves resolving method and property calls at run time, as opposed to

compile time.
The Automation interfaces in X-Stream based DSOs use primarily the latter: Dynamic binding. From many

programming languages (VB, VBScript, etc.) this is transparent. But when you are developing applications in C++,

which does not provide late-binding natively, the use of a “helper” class is required. This is demonstrated below:

#include

"stdafx.h"

#include

"AtlBase.h"

CComModule _Module;

#include

"AtlCom.h"


CComPtr spDso;
CComDispatchDriver ddDso;

// dispatch ptr. to root of object model (app)

int

main(

int

argc,

char

* argv[])

{
printf("Hello X-Stream World!\n");

::CoInitialize(NULL);

HRESULT hr = spDso.CoCreateInstance(L"LeCroy.XStreamDSO");

if

(SUCCEEDED(hr))

{

ddDso = spDso;


// perform an Auto-Setup (app.Autosetup)

hr = ddDso.Invoke0(L"AutoSetup");


// retrieve a Dispatch ptr. to the app.Display object

CComVariant displayPtr;

hr = ddDso.GetPropertyByName(L"Display", &displayPtr);

CComDispatchDriver ddDisplay(displayPtr.pdispVal);


// enter Dual-grid mode (app.Display.GridMode = "Dual")

hr = ddDisplay.PutPropertyByName(L"GridMode", &CComVariant("Dual"));

}

return

0;

}