User Tools

Site Tools


using_windows_dlls_not_created_in_clarion_for_windows.htm
Navigation:  How To's and Troubleshooting > How to… >====== Using Windows DLLs NOT Created in Clarion ====== Previous pageReturn to chapter overviewNext page

NewC7.jpg

You can use Windows .DLLs which have not been created with Clarion if you know the prototypes for the .DLL's procedures and functions. See the Programmer's Guide article on Multi-Language Programming for more information on this topic.

If the source language prototypes are known, then equivalent Clarion prototypes must be created and included in a CLARION program's MAP for all referenced DLL procedures and functions. Also, Clarion requires a Library (.LIB) file in the Project Tree under Library and Object files. This Library file entry enables the linker to resolve the procedure and function references in the .DLL.

If you have a Windows DLL (not created with Clarion) that you want to use in a CLARION program, then the following steps are required to enable the CLARION program to access the DLL's procedures and functions:

·Create Equivalent Clarion Language Prototypes.

·Create a Clarion Library (.LIB ) File for the DLL.

·Reference the Library (.LIB) File in the Project System.

Create Equivalent Clarion Language Prototypes

Prototypes for any referenced .DLL procedures and functions must be in the CLARION program's MAP structure. Procedures and functions written in a language other than Clarion can still be referenced in a Clarion program by creating an equivalent Clarion prototype. The prototypes are placed in a MODULE structure which identifies the name of the DLL's library as the MODULE parameter. For example, if the DLL name is MY.DLL then the module structure would be:

MODULE('MY.LIB')

There are several issues to consider when creating equivalent prototypes in Clarion which are dependent upon a DLL's source code language. A primary consideration is relating equivalent data types in the other language to Clarion. Equivalent data types can be determined by considering the “underlying” machine data type represented by each language data type. For example, the CLARION Language Reference identifies the Clarion data type SREAL as a “four-byte signed floating point”.

The following is an example of C and C++ code data type equivalents.

     unsigned char       =⇒ BYTE

     short               =⇒ SHORT

     unsigned short      =⇒ USHORT

     long                =⇒ LONG

     unsigned long       =⇒ ULONG

     float               =⇒ SREAL

     double              =⇒ REAL

A Clarion GROUP is roughly equivalent to a C or C++ struct. For example:

   Struct1         GROUP              ! Struct1 is defined as a GROUP

   ul1               ULONG            ! containing two ULONG values

   ul2               ULONG

                   END

This form of definition reserves space for Struct1 and is equivalent to the C definition:

     struct {

       unsigned long  ul1;

       unsigned long  ul2;

     } Struct1;

A second important prototyping consideration is the procedure/ function calling convention utilized by another language. Clarion provides support for three different calling conventions: PASCAL, C, and TopSpeed's Register Based.

Create a Clarion Library .LIB File for the DLL.

You can create a .LIB file for the DLL using the LIBMAKER.EXE utility program that comes with Clarion as one of the example programs. Simply run the program, select the .DLL and have it automatically create the .LIB file for you.

Reference the .LIB File in the Project System.

You must place the Library (.LIB) file in the Project Tree under Library and Object files for any Project that will use the .DLL.

using_windows_dlls_not_created_in_clarion_for_windows.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1