Nondrawable objects provide access to the enormous processing power of IDL, but do not provide IDL drawing capabilities. This is useful for applications that need the data manipulation capabilities of IDL, but have no need for, or have independent drawing capabilities.

Hello World COM Example with Custom Method


The following simple example creates an IDL object with a single function method that accepts one argument, and walks through the process of exporting the object using the Export Bridge Assistant. Once the export files are created, a simple Visual Basic .NET console application shows how to access the object method and capture its output.

Complete the following steps to duplicate this example.

  1. In an IDL Editor window, copy in the following code and save the file as helloworldex__define.pro in a directory in your IDL path:
; Method returns message based on presence or
; absence of argument.
FUNCTION helloworldex::HelloFrom, who
  IF (N_ELEMENTS(who) NE 0) THEN BEGIN
  message = "Hello World from " + who
  RETURN, message
  ENDIF ELSE BEGIN
  message = 'Hello World'
  RETURN, message
  ENDELSE
END
 
; Init returns object reference on successful
; initialization.
FUNCTION helloworldex::INIT
  RETURN, 1
END
 
; Object definition.
PRO helloworldex__define
  struct = { $
  helloworldex, $
  who: '' , $
  message: ' ' $
  }
END

Note: It is a good idea to test the functionality of an object before exporting it. After compiling the file, enter the following lines at the command line and make sure the output is what is expected for this object.

ohello = OBJ_NEW("HELLOWORLDEX")
PRINT, ohello->HelloFrom()
PRINT, ohello->HelloFrom('Mr. Bill')
  1. Open the Export Bridge Assistant by entering IDLEXBR_ASSISTANT at the command line.
  2. Select to create a COM export object by selecting File > New Project > COM and browse to select the helloworldex__define.pro file. Click Open to load the file into the Export Assistant.

Note: Export Bridge Assistant details are available in Specifying Information for Exporting. Refer to that section if you need more information about the following steps.

  1. The top-level project entry in the left-hand tree panel is selected by default.

There is no need to modify the default properties shown in the right-hand property panel, but you can enter different values if desired. Set other export object characteristics as described in the following table. Select the tree view item listed in the left column to configure the related properties in the right column.

Tree View Item

Parameter Configuration

IDL Export Bridge Project

Accept the default value or make changes as desired:

  • Output classname
  • Process name
  • Output directory

helloworldex

Drawable object equals False

HELLOFROM method

Output method name: Accept the default value, HELLOFROM

Return Type: BSTR since this function method returns a string message (as defined in the IDL object definition structure)

Array: False since this method returns a single string, not an array

Export: True

WHO argument

Mutability: In since the argument is not passed back to the caller

Type: BSTR since this argument is defined as a string in the IDL object definition

Array: False

Export: True

  1. Save the project by selecting File > Save project. Accept the default name and location or make changes as desired.
  2. Verify that the object elements you want to export are listed in the Export log panel. If the expected items are not present, one or more items may still have an UNSPECIFIED field value that must be changed.
  3. Build the export object by selecting Build > Build object. The Build log panel shows the results of the build process. For a nondrawable object, .tlb and .dll files (named based on the object name) are created in the Output directory.
  4. Register the .dll using regsvr32 helloworldex.dll. See COM Registration Requirements for details if needed. (If you receive an error 0x80070005, you may need to run the Command Prompt application with Administrator privileges.)
  5. Create a new Visual Basic .NET console application and import a reference to the COM library named helloworldexLib 1.0 Type Library.
  6. Replace the default module code with the text in the file referenced below. See code comments for details.

Example Code

The text file for this example, com_export_helloex_doc.txt, is located in the examples/doc/bridges/COM subdirectory of the IDL distribution. This Visual Basic .NET code can be copied from the text file and adopted for use in your COM environment.

After building the solution and starting without debugging, the console window appears with the output messages.