Next: GNAT and Windows Resources, Previous: Ada DLLs and Finalization, Up: Mixed-Language Programming on Windows [Contents][Index]
To use the services exported by the Ada DLL from another programming language (e.g., C), you have to translate the specs of the exported Ada entities in that language. For instance in the case of API.dll, the corresponding C header file could look like:
extern int *_imp__count; #define count (*_imp__count) int factorial (int);
It is important to understand that when building an Ada DLL to be used by other Ada applications, you need two different specs for the packages contained in the DLL: one for building the DLL and the other for using the DLL. This is because the DLL calling convention is needed to use a variable defined in a DLL, but when building the DLL, the variable must have either the Ada or C calling convention. As an example consider a DLL comprising the following package API:
package API is Count : Integer := 0; ... -- Remainder of the package omitted. end API;
After producing a DLL containing package API, the spec that must be used to import API.Count from Ada code outside of the DLL is:
package API is Count : Integer; pragma Import (DLL, Count); end API;
• Creating the Definition File: | ||
• Using gnatdll: | ||