Sample IDL Object for COM
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:
- Open the Export Bridge Assistant by entering IDLEXBR_ASSISTANT at the command line.
- 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.
Note: Export Bridge Assistant details are available here, Using the Export Bridge Assistant. Refer to that section if you need more information about the following steps. -
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.
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
- Save the project by selecting File > Save project. Accept the default name and location or make changes as desired.
- 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.
- Register the .dll using regsvr32 idlexfoo.dll. See COM Registration Requirements for details if needed.
See the language-specific sections for information on how to create this object in your application: