Next: , Up: Using DLLs with GNAT

F.8.1 Creating an Ada Spec for the DLL Services

A DLL typically comes with a C/C++ header file which provides the definitions of the routines and variables exported by the DLL. The Ada equivalent of this header file is a package spec that contains definitions for the imported entities. If the DLL you intend to use does not come with an Ada spec you have to generate one such spec yourself. For example if the header file of API.dll is a file api.h containing the following two definitions:


int some_var; int get (char *);

then the equivalent Ada spec could be:


with Interfaces.C.Strings; package API is use Interfaces; Some_Var :; function Get (Str : C.Strings.Chars_Ptr) return; private pragma Import (C, Get); pragma Import (DLL, Some_Var); end API;

Note that a variable is always imported with a DLL convention. A function can have C, Stdcall or DLL convention. For subprograms, the DLL convention is a synonym of Stdcall (see Windows Calling Conventions).