Introduction  Appendix A: Conversion Tables

Chapter 8: Using Shared Libraries

Implementing custom C/C++ functions in ODL projects

To call C/C++ shared library functions from ODL applications, follow these steps:

  1. Create a collection of desired C/C++ functions callable from ODL. All functions must have a return value type of int.

  2. Use a C++ compiler to compile the C/C++ functions collection into library form.

  3. Create a custom C/C++ function definition file, which is loaded by the ODL engine, and correctly maps ODL calls to the custom C functions.

    You must save this file as definition.bdl, and the file must be in the following format for the BIDL code generator to properly generate the appropriate code. If the definition file is incorrectly formatted, you receive an error when executing the BIDL code generator.

    Definition file format:

    interface name
    
    {
    
    [import(“custom-c-function-name”)]
    
    int corresponding-odl-function-name (argument type argument name, ...);
    
    
    
    [import(“custom-c-function-name”)]
    
    int corresponding-odl-function-name (argument type argument name, ...);
    
    
    
    [import(“custom-c-function-name”)]
    
    int corresponding-odl-function-name (argument type argument name, ...);
    
    
    
    .
    
    .
    
    .
    
    };
    

    Repeat the definitions to define all functions and function arguments. Save the file with a .bdl file name extension.

    Example definition file:

    interface abc2002
    
    {
    
    [import(“pepperBrook”)]int myfunction0(char hlschar,
    
                                           short slshort,
    
                                           int hlsint,
    
                                           long hlslong);
    
    [import(“shadyMeadow”)]int myfunction1(unsigned char hlschar,
    
                                           unsigned short slshort,
    
                                           unsigned int hlsint,
    
                                           unsigned long hlslong);
    
    [import(“mayWind”)]int myfunction2(char *hlschar,
    
                                       short *slshort,
    
                                       int *hlsint,
    
                                       long *hlslong);
    
    [import(“dawnHaven”)]int myfunction3(unsigned char *hlschar,
    
                                         unsigned short *slshort,
    
                                         unsigned int *hlsint,
    
                                         unsigned long *hlslong);
    
    [import(“creekside”)]int myfunction4(string sl, string *ps2);
    
    );
    

    When you create the custom definition file, note that:

  4. Run the BIDL code generator along with the function definition file and the provided template file to create code for the mapping library.

    ims bidl [function def file] [template file] [output filename]
    

    For example:

    ims bidl definition.bdl bidlTemplate.cpp test.cpp
    

    NoteThe location of the ims wrapper script must be in your path, or you must enter the complete path when you enter the ims command.

  5. Compile the library.

    Use the mapping .cpp file generated by the BIDL code generator, along with your make file, custom DLL, and ims54odl library to compile the custom library that contains your custom C/C++ functions.

  6. Configure the ODL application using the Configurator. Specify the resulting .cpp file by modifying the configuration values for the associated ODL application (right-click the application and select Properties), on the Advanced tab, in the External Libraries section. Identify the alias name in the Name field, and enter the actual library name in the Library field.

    Be sure that the ODL project file also references the resulting library. For example:

    #dll libx “aliaslib.dll” //alias for actual library
    
    
    
    clinit()
    
    {
    
    	.
    
    	.
    
    
    




Copyright © 2005. Sybase Inc. All rights reserved. Appendix A: Conversion Tables

View this book as PDF