Wrapper Generation Example
The following example exports a simple IDL object that has no properties or methods and demonstrates the configuration necessary to initialize a COM or Java client application to use the exported object. First, create the IDL source object.
- Create a file named
helloworld__define.pro(within your IDL path) containing the following code: - Open the Assistant by entering IDLEXBR_ASSISTANT at the command line.
FUNCTION helloworld::INIT RETURN, 1 END PRO helloworld__define struct = {helloworld, $ dummy:0b $ ; dummy structure field, not a property } ENDThis is the source object definition file that you will export using the Export Bridge Assistant.
See one of the following:
COM Wrapper Object Generation and Use
The following example exports and uses the helloworld object in a simple Visual Basic .NET console application. After creating the object definition file and launching the Assistant as described in Wrapper Generation Example, complete the following steps.
- Select to create a COM export object by selecting File → New Project → COM and browse to select the
helloworld__define.profile. Click Open to load the file into the Export Assistant. - 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. Select the tree view item listed in the left column to configure the related properties in the right column.
- 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, .
tlband .dllfiles (named based on the object name) are created in the Output directory. - Register the .
dllusingregsvr32 helloworld.dll. See COM Registration Requirements for details if needed. - Create a new Visual Basic .NET console application and add a reference to the COM library named
helloworldLib 1.0 Type Library. Select Project → Add Reference, and click on the COM tab. Select thehelloworld.dlland click Ok. - Replace the default module code with the following text:
For this simple example, the source object has no properties or methods, so none are exported.
Note
See Specifying Information for Exporting for details on configuring export values.
Imports helloworldLib Module Module1 Dim oHello As New helloworldLib.helloworldClass Sub Main() Try oHello.CreateObject(0, 0, 0) Catch ex As Exception Console.WriteLine(oHello.GetLastError()) Return End Try AddHandler oHello.OnIDLOutput, AddressOf evOutput oHello.ExecuteString("Print, 'Hello World'") End Sub Sub evOutput(ByVal ss As String) Console.WriteLine(ss) End Sub End ModuleIn this example, the stock ExecuteString method is used to print the hello world message. By adding a handler for the OnIDLOutput method, the console application is able to capture and output the information that would typically be printed to the Output window of IDL. After building the solution and starting without debugging, the console window appears with the output messages.
Java Wrapper Object Generation and Use
The following example exports and uses the helloworld object in a simple Java application. After creating the object definition file and launching the Assistant as described in Wrapper Generation Example, complete the following steps.
- Select to create a Java export object by selecting File → New Project → Java and browse to select the
helloworld__define.profile. Click Open to load the file into the Export Assistant. - 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. Select the tree view item listed in the left column to configure the related properties in the right column.
- 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. A subdirectory, named
helloworld(based on the object name), contains the .javaand .classfiles, and is located in the Output directory. - Create a file named
helloworld_example.javathat contains the following code and save the file in thehelloworlddirectory.
|
Tree View Item
|
Parameter Configuration
|
|---|---|
| IDL Export Bridge Project |
Accept the default value or make changes: |
| helloworld |
Drawable object equals False |
For this simple example, the source object has no properties or methods, so none are exported.
Note
See Specifying Information for Exporting for details on configuring export values.
package helloworld; import com.idl.javaidl.*; public class helloworld_example extends helloworld implements JIDLOutputListener { private helloworld hwObj; // Constructor public helloworld_example() { hwObj = new helloworld(); hwObj.createObject(); hwObj.addIDLOutputListener(this); hwObj.executeString("print, 'Hello World'"); } // implement JIDLOutputListener public void IDLoutput(JIDLObjectI obj, String sMessage) { System.out.println("IDL: "+sMessage); } public static void main(String[] argv) { helloworld_example example = new helloworld_example(); } }Note
By default, the Assistant generates a package so any Java routine using an exported wrapper object must include the package name. The second statement,import com.idl.javaidl.*;is also required.For example purposes, the stock method executeString is called, and an output listener is registered to retrieve the IDL output.
The wrapper is compiled and run using the commands below:
Windows Commands to Build and Run the Client
The following commands build and run this Java wrapper example on Windows.
- To compile and run the Java routine, open the Windows Command window by selecting Start → Run and enter
cmdin the textbox. - Use the
cdcommand to change to the directory containing thehelloworlddirectory. For a default Windows installation, the command would be similar to the following: - Reference the classpath of
javaidlb.jarin the compile statement. Enter the following commands (each as a single line), replacingIDL_DIRwith the IDL installation directory, for exampleITT\IDL63:
javac -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" helloworld\helloworld_example.java java -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" helloworld.helloworld_exampleIn both commands, the
.character includes the current directory in the classpath.The first command uses
javacto compile the example client. The path to thehelloworld_example.javafile is specified using a backslash character as a directory separator.The second command uses
javato run the example client. The final argument specifies the package path to thehelloworld_exampleclass file. Note that a.character is used as a separator in the package path. The final argument to the second command intentionally omits the suffix.
After compiling and running the project, the output message will appear in the command window.
UNIX Commands to Build and Run the Client
The following commands build and run this Java wrapper example on UNIX:
source IDL_DIR/bin/bridge_setup javac helloworld/helloworld_example.java java helloworld.helloworld_exampleNote
See Java Requirements for more information on thebridge_setupfile.
The source command adds the necessary directories to the dynamic library path and the classpath.
The second command uses javac to compile the example client. The third command uses java to run the example client. The final argument specifies the package path to the helloworld_example. class file. Note that a . character is used as a separator in the package path. The final argument to the second command intentionally omits the suffix.
After compiling and running the project, the output message will appear.

