LabWindows/CVI

Content Type
Programming Language
Current manual

Generating Files and Code with the ActiveX Server Wizard

Generating Files and Code with the ActiveX Server Wizard

When used in ANSI C, you can think of a COM interface as a table of function pointers and a COM object as being similar to a user interface control that has attributes and functions. A significant portion of COM programming consists of coding a number of generic tasks and writing boilerplate system code. Consider the following points when you create a COM application:

  • All COM interfaces are derived from an interface called IUnknown that provides basic functionality such as verifying object identity, getting information about the interfaces implemented by the object, and managing the lifetime of the object. The IUnknown interface contains the following three functions, which LabWindows/CVI automatically creates for ActiveX servers you generate using the ActiveX Server Wizard:
    • QueryInterface—The CA_ServerQueryInterface function in the ActiveX Library implements this function.
    • AddRef—The CA_ServerAddRef function in the ActiveX Library implements this function.
    • Release—The CA_ServerRelease function in the ActiveX Library implements this function.

      The implementation of these functions is critical. The IUnknown interface is based on well-tested boilerplate code and is reused for all the interfaces in the application.
  • All well-written COM applications should perform self-registration. This requirement means that a COM application should contain the code to register and unregister itself on a particular computer. Given the objects and interfaces in a COM application, this task consists of adding and deleting a number of keys and values in the system registry.
  • Most COM applications contain embedded libraries called type libraries that programming environments use to determine the interfaces and objects of the COM applications. The LabWindows/CVI ActiveX Controller Wizard reads the type libraries of ActiveX applications and generates wrapper code organized as a LabWindows/CVI instrument driver that can be used to control the servers.
  • COM applications that are Dynamic Link Libraries (DLLs) must export the following four functions:
  • COM interfaces and coclasses are written in a language called Interface Definition Language (IDL). This language is very similar to C and C++. The IDL code then is compiled in the Microsoft IDL (MIDL) compiler to build the type library, which is embedded in the COM application.

The preceding tasks—coding IUnknown functions, writing self-registration code, embedding type libraries and writing/compiling IDL—might be new to application programmers. Therefore, LabWindows/CVI provides tools to simplify COM application development.

To build an ActiveX server in LabWindows/CVI, complete the following steps:

  1. Create a new project or open an existing project.
  2. Select Tools»Create ActiveX Server to launch the Create ActiveX Server Wizard.
  3. Use the Create ActiveX Server Wizard to specify settings that LabWindows/CVI uses to make the project an ActiveX server project.
  4. When you finish specifying settings for the ActiveX server project, the Edit ActiveX Server tool appears. You also can select Tools—Edit ActiveX Server to open the tool. Use the Edit ActiveX Server tool to specify ActiveX interfaces and objects and to generate the ActiveX server code.
  5. Implement the entry-point function, ActiveX server functions, and callback functions in a source file. These functions are prototyped in the generated include file.
  6. Add the implementation source file to the project and build the project.
Was this information helpful?