* Windows Calling Conventions::
* Introduction to Dynamic Link Libraries (DLLs)::
* Using DLLs with GNAT::
-* Building DLLs with GNAT::
* Building DLLs with GNAT Project files::
+* Building DLLs with GNAT::
* Building DLLs with gnatdll::
* GNAT and Windows Resources::
* Debugging a DLL::
@item
It is not possible to link against Microsoft libraries except for
-import libraries. The library must be built to be compatible with
-@file{MSVCRT.LIB} (/MD Microsoft compiler option), @file{LIBC.LIB} and
-@file{LIBCMT.LIB} (/ML or /MT Microsoft compiler options) are known to
-not be compatible with the GNAT runtime. Even if the library is
-compatible with @file{MSVCRT.LIB} it is not guaranteed to work.
+import libraries. Interfacing must be done by the mean of DLLs.
@item
When the compilation environment is located on FAT32 drives, users may
If you use @command{gcc} to compile the non-Ada part of your application,
there are no Windows-specific restrictions that affect the overall
-interoperability with your Ada code. If you plan to use
-Microsoft tools (e.g.@: Microsoft Visual C/C++), you should be aware of
-the following limitations:
-
-@itemize @bullet
-@item
-You cannot link your Ada code with an object or library generated with
-Microsoft tools if these use the @code{.tls} section (Thread Local
-Storage section) since the GNAT linker does not yet support this section.
-
-@item
-You cannot link your Ada code with an object or library generated with
-Microsoft tools if these use I/O routines other than those provided in
-the Microsoft DLL: @code{msvcrt.dll}. This is because the GNAT run time
-uses the services of @code{msvcrt.dll} for its I/Os. Use of other I/O
-libraries can cause a conflict with @code{msvcrt.dll} services. For
-instance Visual C++ I/O stream routines conflict with those in
-@code{msvcrt.dll}.
-@end itemize
-
-@noindent
-If you do want to use the Microsoft tools for your non-Ada code and hit one
-of the above limitations, you have two choices:
+interoperability with your Ada code. If you do want to use the
+Microsoft tools for your non-Ada code, you have two choices:
@enumerate
@item
@item
Or you can encapsulate your Ada code in a DLL to be linked with the
other part of your application. In this case, use GNAT to build the DLL
-(@pxref{Building DLLs with GNAT}) and use the Microsoft or whatever
-environment to build your executable.
+(@pxref{Building DLLs with GNAT Project files}) and use the Microsoft
+or whatever environment to build your executable.
@end enumerate
@node Windows Calling Conventions
@findex Stdcall
@findex APIENTRY
+This section pertain only to Win32. On Win64 there is a single native
+calling convention. All convention specifiers are ignored on this
+platform.
+
@menu
* C Calling Convention::
* Stdcall Calling Convention::
@noindent
The argument @option{-largs -lAPI} at the end of the @command{gnatmake} command
-tells the GNAT linker to look first for a library named @file{API.lib}
-(Microsoft-style name) and if not found for a libraries named
-@file{libAPI.dll.a}, @file{API.dll.a} or @file{libAPI.a}.
-(GNAT-style name). Note that if the Ada package spec for @file{API.dll}
-contains the following pragma
+tells the GNAT linker to look for an import library. The linker will
+look for a library name in this specific order:
+
+@enumerate
+@item @file{libAPI.dll.a}
+@item @file{API.dll.a}
+@item @file{libAPI.a}
+@item @file{API.lib}
+@item @file{libAPI.dll}
+@item @file{API.dll}
+@end enumerate
+
+The first three are the GNU style import libraries. The third is the
+Microsoft style import libraries. The last two are the DLL themself.
+
+Note that if the Ada package spec for @file{API.dll} contains the
+following pragma
@smallexample @c ada
pragma Linker_Options ("-lAPI");
@code{lib}.
@end enumerate
+@node Building DLLs with GNAT Project files
+@section Building DLLs with GNAT Project files
+@cindex DLLs, building
+
+@noindent
+There is nothing specific to Windows in the build process.
+@pxref{Library Projects}.
+
+@noindent
+Due to a system limitation, it is not possible under Windows to create threads
+when inside the @code{DllMain} routine which is used for auto-initialization
+of shared libraries, so it is not possible to have library level tasks in SALs.
+
@node Building DLLs with GNAT
@section Building DLLs with GNAT
@cindex DLLs, building
$ gnatmake main -Iapilib -bargs -shared -largs -Lapilib -lAPI
@end smallexample
-@node Building DLLs with GNAT Project files
-@section Building DLLs with GNAT Project files
-@cindex DLLs, building
-
-@noindent
-There is nothing specific to Windows in the build process.
-@pxref{Library Projects}.
-
-@noindent
-Due to a system limitation, it is not possible under Windows to create threads
-when inside the @code{DllMain} routine which is used for auto-initialization
-of shared libraries, so it is not possible to have library level tasks in SALs.
-
@node Building DLLs with gnatdll
@section Building DLLs with gnatdll
@cindex DLLs, building
@end menu
@noindent
-Note that it is preferred to use the built-in GNAT DLL support
-(@pxref{Building DLLs with GNAT}) or GNAT Project files
-(@pxref{Building DLLs with GNAT Project files}) to build DLLs.
+Note that it is preferred to use GNAT Project files
+(@pxref{Building DLLs with GNAT Project files}) or the built-in GNAT
+DLL support (@pxref{Building DLLs with GNAT}) or to build DLLs.
This section explains how to build DLLs containing Ada code using
@code{gnatdll}. These DLLs will be referred to as Ada DLLs in the
-- --
-- B o d y --
-- --
--- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
begin
if X = 0.0 then
+
+ -- The normalized exponent of zero is zero, see RM A.5.2(15)
+
Frac := X;
Expo := 0;
- -- More useful would be defining Expo to be T'Machine_Emin - 1 or
- -- T'Machine_Emin - T'Machine_Mantissa, which would preserve
- -- monotonicity of the exponent function ???
-
-- Check for infinities, transfinites, whatnot
elsif X > T'Safe_Last then
end if;
-- Ax < R_Power (N)
+
end loop;
-- 1 <= Ax < Rad
end if;
-- R_Neg_Power (N) <= Ax < 1
+
end loop;
end if;
-- Scaling --
-------------
- -- Return x * rad ** adjustment quickly,
- -- or quietly underflow to zero, or overflow naturally.
+ -- Return x * rad ** adjustment quickly, or quietly underflow to zero,
+ -- or overflow naturally.
function Scaling (X : T; Adjustment : UI) return T is
begin
end if;
-- -Log_Power (N) < Ex <= 0
+
end loop;
-- Ex = 0
end loop;
-- Ex = 0
+
end if;
return Y;
else
Decompose (X, X_Frac, X_Exp);
- -- A special case, if the number we had was a negative power of
- -- two, then we want to add half of what we would otherwise add,
- -- since the exponent is going to be reduced.
+ -- A special case, if the number we had was a negative power of two,
+ -- then we want to add half of what we would otherwise add, since the
+ -- exponent is going to be reduced.
-- Note that X_Frac has the same sign as X, so if X_Frac is -0.5,
- -- then we know that we have a negative number (and hence a
- -- negative power of 2).
+ -- then we know that we have a negative number (and hence a negative
+ -- power of 2).
if X_Frac = -0.5 then
return X + Gradual_Scaling (X_Exp - T'Machine_Mantissa - 1);
-- one read, but small enough so that all floating point object sizes
-- are a multiple of the Float_Word'Size.
- -- The following conditions must be met for all possible
- -- instantiations of the attributes package:
+ -- The following conditions must be met for all possible instantiations
+ -- of the attributes package:
-- - T'Size is an integral multiple of Float_Word'Size
type Rep_Index is range 0 .. 7;
Rep_Words : constant Positive :=
- (T'Size + Float_Word'Size - 1) / Float_Word'Size;
- Rep_Last : constant Rep_Index := Rep_Index'Min
- (Rep_Index (Rep_Words - 1), (T'Mantissa + 16) / Float_Word'Size);
+ (T'Size + Float_Word'Size - 1) / Float_Word'Size;
+ Rep_Last : constant Rep_Index :=
+ Rep_Index'Min
+ (Rep_Index (Rep_Words - 1),
+ (T'Mantissa + 16) / Float_Word'Size);
-- Determine the number of Float_Words needed for representing the
-- entire floating-point value. Do not take into account excessive
-- padding, as occurs on IA-64 where 80 bits floats get padded to 128