To call C/C++ shared library functions from ODL applications, follow these steps:
Create a collection of desired C/C++ functions callable from ODL. All functions must have a return value type of int.
Use a C++ compiler to compile the C/C++ functions collection into library form.
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.
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, ...);
.
.
.
};
name – user-defined name for the custom collection.
custom-c-function-name – custom C/C++ function name, mapped to the corresponding-odl-function-name in the ODL application.
corresponding-odl-function-name – a corresponding ODL function mapped to the custom C/C++ function. Call this in the ODL application to call the custom C/C++ function in your library.
argument type – matches the custom custom-c-function-name.
argument name – matches the custom custom-c-function-name.
Repeat the definitions to define all functions and function arguments. Save the file with a .bdl file name extension.
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:
The return type of each function must be int.
For each C/C++ function, there is an ODL function mapping. In the example definition file, the C function pepperBrook() is mapped to the ODL function myfunction0. Within the ODL project, the C function pepperBrook() is callable only through the myfunction0 alias.
The signatures of the C functions and ODL functions must match up. For the custom library to work correctly, the definition file must accurately define the custom C functions argument. In the case of the example C function pepperBrook(), it takes in a char, short, int, long. On the ODL project side, the C function can be called by the corresponding ODL function name, myfunction0 and with the char, short, int, and long argument variables passed to it.
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
The location of the ims wrapper script
must be in your path, or you must enter the complete path when you
enter the ims command.
function def file – used by the BIDL code generator to create a .cpp file loaded by the ODL engine that correctly maps the ODL calls to custom C/C++ functions. In the example given, this is definition.bdl.
template file – contains header files required by the BIDL code generator. This file—bidlTemplate.cpp—is located in x:\Sybase\ImpactServer-5_4\include\IMPACT\BIDL on Windows and in <installation_directory>/Sybase/ImpactServer-5_4/include/IMPACT/BIDL on UNIX. Do not modify the template file.
output filename – the mapping library code used when compiling the custom C/C++ library. In the example shown, this is test.cpp.
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.
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. |
![]() |