Previous IDL Connectivity Bridges: COM Object Creation Next

Sample IDL Object

The COM CreateObject method creates an instance of an underlying IDL object and calls its Init method with any specified parameters (see CreateObject for details). Through this object instance, you have access to the properties and methods of the object as well as the underlying IDL process.

The following samples rely upon an IDL object named idlexfoo__define.pro containing the following code:

; The Init method expects three parameters:   
; a string, a 32-bit long, and an array which has   
; 2 rows & 3 columns, containing 32-bit long values.    
; The ::Init method can also be called without any parameters.  
  
FUNCTION idlexfoo::Init, parmStr, parmVal, parmArr, _EXTRA=e  
  
   IF (N_ELEMENTS(parmStr) EQ 1) THEN BEGIN  
      IF ( SIZE(parmStr,/type) NE 7 ) THEN BEGIN  
         PRINT, 'IDLexFoo::Init, parmStr is not a STRING'  
         HELP, parmStr  
         RETURN, 0  
      ENDIF  
   ENDIF  
  
   IF (N_ELEMENTS(parmVal) EQ 1) THEN BEGIN  
      IF ( (SIZE(parmVal,/type) NE 3) ) THEN BEGIN  
         PRINT, 'IDLexFoo::Init, parmVal is not a LONG'  
         HELP, parmVal  
         RETURN, 0  
      ENDIF  
   ENDIF  
      
   nElms = N_ELEMENTS(parmArr)  
   IF (nElms GT 0) THEN BEGIN  
      IF ( (nElms NE 6) OR (size(parmArr,/type) NE 3) ) THEN BEGIN  
         PRINT, 'IDLexFoo::Init, parmArr is not a ARR(3,2) of 
LONG)'  
         HELP, parmArr  
         RETURN, 0  
      ENDIF  
   ENDIF  
  
   RETURN, 1  
END  
  
; Object definition.  
PRO idlexfoo__define  
   ; Create [col, row] 32-bit long array.  
   initArr = LONARR(3,2)   
   struct = {idlexfoo, $  
      parmStr: '', $  
      parmVal: 0L, $  
      parmArr: initArr $   
   }  
END  

Export the Sample IDL Object

You will need to create the necessary wrapper object files by using the Export Bridge Assistant to generate them. Once you have created the object definition file, idlexfoo__define.pro, complete the following steps:

  1. Open the Export Bridge Assistant by entering IDLEXBR_ASSISTANT at the command line.
  2.  

  3. Select to create a COM export object by selecting File  New Project  COM and browse to select the idlexfoo__define.pro file. Click Open to load the file into the Export Assistant.
  4.  


    Note
    Export Bridge Assistant details are available in Using the Export Bridge Assistant. Refer to that section if you need more information about the following steps.

     

  5. The top-level project entry in the left 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. There are no other parameters that need to be defined for this object.
  6.  

    Table B-4: Example Export Object Parameters

    Table B-4: Example Export Object Parameters
    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

     

  7. Save the project by selecting File Save project. Accept the default name and location or make changes as desired.
  8.  

  9. 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.
  10.  

  11. Register the .dll using regsvr32 idlexfoo.dll. See COM Registration Requirements for details if needed.

See the language-specific section for information on how to create this object in your application:

  IDL Online Help (March 06, 2007)