PRODUCT : Borland C++ NUMBER : 1536 VERSION : 1.0 OS : OS/2 DATE : October 25, 1993 PAGE : 1/2 TITLE : Calling 16 bit DLL's in Borland C++ for OS/2 Title: Calling 16-Bit DLL's from 32-Bit Borland OS2 Applications Suppose you have a 16-bit OS/2 DLL (like many database DLL's) and you want to use it from your 32-bit OS/2 application. Here's what you'll need to do for prototypes of the DLL's functions: * 16-bit functions taking/returning an int should be prototyped as taking/returning a short, since 16-bit int's are now considered 'short' (USHORT or APIRET16 are the typedefs in OS2DEF.H) * The function should be declared as APIENTRY16, or, _far16 _pascal * Any pointers that the function takes as parameters must be declared as _far16 Example: Former prototype in foo.h (foo.dll's associated header file): int FooData(char *, int); New prototype for linking 32-16 (in your BC++ program): short _far16 _pascal FooData(char _far16 *, short); Note: Don't use ... char * _far16 ... It's easy to make that mistake since IBM's pointers are declared with _Seg16 after the '*', e.g. char * _Seg16. If you wanted to use the types declared in os2def.h, it would be: APIRET16 APIENTRY16 FooData(PCHAR16, SHORT); The compiler will take care of the address conversions for the function and the data being passed. Notes: Most DLL's need the _pascal calling convention. Sybase is an PRODUCT : Borland C++ NUMBER : 1536 VERSION : 1.0 OS : OS/2 DATE : October 25, 1993 PAGE : 2/2 TITLE : Calling 16 bit DLL's in Borland C++ for OS/2 exception, Sybase DLL functions need to be called as _cdecl. It's difficult to pass a 32bit function pointer to be executed from a 16-bit DLL ("callback") and how to do it is beyond the scope of this document. See \bcos2\examples\thunk for more information. Functions in a 16bit DLL that take variable argument lists (a la printf) are unworkable. The compiler cannot know to convert their addresses. An array of pointers cannot be converted, for the same reason. DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.