Home > Support > Knowledge Base > IVI COM Client Examples > Visual C++

Developing a Visual C++ IVI-COM Client

This example describes the steps required to access an IVI-COM driver from a Visual C++ MFC application. To illustrate this process a simple project will be built. The VektrexScope driver is used in the example.

Step 1: Creating the Project

Use Visual C++ to create a new MFC application (exe). A simple dialog-based program will demonstrate the concepts.

 

  Step 2: Design a Dialog Box

Design a dialog box with a button to get the Number of Averages, an edit box to display the result and a close button.

 

  Step 3: Turn on COM

Add a call to AfxOleInit in the CCPlusPlusClient class’s InitInstance function, as shown below.

 

 

  Step 4: Import the COM Components

Import the components using the #import command and the DLL names in the main header file (CplusPlusClient.h in this example). Note that the IVI DLLs need no path information since they are in locations known to C++ due to path information installed by the VIVID installer. The driver object needs a specified path unless it is moved to a location like the windows directory.

 

 

Step 5: Create an Instance of the Driver Object

Smart pointers are used to communicate with the instrument. These C++ classes perform a similar function for drivers as the CString class does for the handling of strings (hiding the allocations, de-allocations, etc). Appropriate smart pointers are available to the project following the #import statements of Step 4. When an instance of an IVI-COM object is created, a pointer to the default interface is returned. For the VektrexScope object, that interface is IVektrexScope and the smart pointer corresponding to that interface is IVektrexScopePtr. A private member variable needs to be added to the CCplusplusClientDlg class to hold the pointer, as shown below. This class definition is found in the CplusplusClientDlg.h file.

 

 

Now that a pointer is defined to access the driver object, the code to create and initialize the instance can be inserted into the OnInitDialog function.

 

 

Step 6: Using the Driver

Our simple program needs to call two driver functions. One is when the Get Number of Averages button is pressed, as shown below. The member variable m_Information is associated with the dialog box’s edit control.

 

 

The other is when the Close button is pressed, as shown below.

 

 

Intellisense provides the developer with information on using the driver as the code is written.

This example has shown how to create a client application in Visual Basic using the instrument specific interfaces. Note that this application is not using any of the interchangeability features (it is not using the compliant interfaces and it references a particular driver, VektrexScope, directly).

 

Copyright 2006, Vektrex, (858) 558-8282,