Aonix > Support > Ada > FAQ >

 

Ada Support FAQ

 

ObjectAda for Windows
How do I find more information on errors in my source code that are flagged by the compiler if I don't have a copy of the LRM?
What is the difference between DOS and Console applications?
Can I bind to C++ static and virtual class members?
I get the error "Error 49: Bad calling convention" when I call ObjectAda DLLs using Visual Basic.
How can I access a serial port and other devices?
Can I create a redistributable library with ObjectAda without revealing my source code?
I don't understand what is meant by a "target" in a project. Does this mean that OAW can target applications to different processors or operating systems?
Does ObjectAda for Windows support task priorities?
Where can I find sample programs to help me get started?
Can I modify the default mapping of Ada task priorities to Win32 thread priorities?
What is the difference between a GUI Builder project and an OAW project?
I'm trying to use Win32 common controls, but I get link errors. Why?
What if I want to statically link and make calls into Ada code from my C main program?
What is the best way to call Ada from C or C++?
Can the GUI Builder produce an executable application from the application source code it generates?
Does the GUI Builder support ActiveX controls?
Can I use the OAW debugger to debug an Ada DLL?
Can I access network services from OAW?
How can I use a CM tool with OAW?
Can I use third-party editors with OAW?
 
General
What is the proper usage of pragma Export?
How do I use the ObjectAda command line tools to script my application build?
 
Tools
Is a profiler available?
The debugger "step" command is "grayed-out" unless the debugger is already running. How can I step to the first executable instruction without setting a breakpoint first?
How do I examine package global data items that are not in the same package as the location of the current breakpoint?
 
ObjectAda Real-Time
How precise is the system timer and does it depend on the CPU speed?
Does ObjectAda ETS provide graphical timing analysis?
Are there ways to lock memory to control paging? For instance, can I lock a 40meg chunk of data into memory to prevent it being swapped out?

ObjectAda for Windows
How do I find more information on errors in my source code that are flagged by the compiler if I don't have a copy of the LRM?
^ RETURN TO TOP ^
  If you are using the ObjectAda IDE, you can navigate to the appropriate section of the online LRM by double clicking on the error message from the build tab in the output message area at the bottom of the ObjectAda IDE main window. The same operation will be performed if you press F1 after selecting an error message.

What is the difference between DOS and Console applications?
^ RETURN TO TOP ^
  DOS and Console applications look and operate identically. The difference is that a Console application runs only in a Windows 95 or NT console window (sometimes called a "DOS Box") and will not run under true DOS. Console applications can be made with any version of OAW, however the OAW environment does not have support for applications to run under true DOS.

Can I bind to C++ static and virtual class members?
^ RETURN TO TOP ^
 

The following example illustrates how Ada can be interfaced to C++ static class members

Class MyClass {
static int TheAnswer;
public:
static int Question(); {
return TheAnswer;
}
MyClass
TheAnswer = 42;
}
};

int MyClass::TheAnswer;
MyClass mc;
void dummy() {
mc.Question();
}

Note
: The function dummy() is present only to avoid the removal of the otherwise unreferenced member function.

-- Ada source
with Ada.Text_IO;
procedure Test is
function Question return integer;
pragma Import (Cdecl,
Question,
Link_Name => "?Question@MyClass@@SAHXZ"); -- decorated name
begin
Ada.Text_IO.Put_Line("The answer is" & integer'image(Question);
end Test;
-- end Ada source

Note
: The "decorated name" supplied as argument to Link_Name may be extracted from an assembler listing of the C++ code or from a link map if it is linked into a program in its own right. For static members, use the convention Cdecl.



The following example illustrates how Ada may be interfaced to C++ virtual class members.

Class MyClass {
int TheAnswer;
public:
int Question(); {
return TheAnswer;
}
MyClass (int Clue) {
TheAnswer = Clue;
}
};

MyClass mc42(42);
MyClass mc69(69);
void cmain(){
mc42.Question();
mc69.Question();
}

-- Ada source code
with Ada.Text_IO;
with System;
procedure Test is
function Question (Class: in System.Address) return integer;
pragma Import (ThisCall,
Question,
Link_Name => "?Question@MyClass@@QAEHXZ"); -- decorated name

type Class_Record is
record
null; -- a dummy declaration
end record;

mc42, mc69: Class_Record;
pragma Import (C, mc42, link_name => "? mc42@@3VMyClass@@A");
pragma Import (C, mc69, link_name => "? mc69@@3VMyClass@@A");

begin
Ada.Text_IO.Put_Line("The answer is" &
integer'image(Question(mc42'address)));
Ada.Text_IO.Put_Line("The answer is" &
integer'image(Question(mc69'address)));
end Test;
-- end Ada source code

The Ada code must pass the address of the class object (mc42 or mc69 in the example above) as the first parameter to the member function and use the convention ThisCall. In this example, the class objects have external linkage and so can be referenced using link names. In other cases (automatic objects for example), the addresses must be conveyed to the Ada code by way of some user-defined mechanism.



I get the error "Error 49: Bad calling convention" when I call ObjectAda DLLs using Visual Basic.
^ RETURN TO TOP ^
  It appears that Visual Basic can only use the STDCALL calling convention when calling a DLL file. By default ObjectAda uses DLL_CDECL for a calling standard when using pragma Export(Dll...). To get Visual Basic to work with ObjectAda correctly, use pragma Export(DLL_STDCALL...).

How can I access a serial port and other devices?
^ RETURN TO TOP ^
  Unlike Windows 3.1, Windows NT/2000 does not allow INT21 or BIOS access to the communication ports. If such access is required, the DDK should be used to develop a driver to carry out the function. However, if the appropriate Windows driver for the device is installed, communication ports can be opened and used via the CreateFile, ReadFile and WriteFile API calls. The following functions are also available for use with communications devices.
  • BuildCommDCB
  • BuildCommDCBAndTimeouts
  • ClearCommBreak
  • ClearCommError
  • CommConfigDialog
  • DeviceIoControl
  • EscapeCommFunction
  • GetCommConfig
  • GetCommMask
  • GetCommModemStatus
  • GetCommProperties
  • GetCommState
  • GetCommTimeouts
  • GetDefaultCommConfig
  • PurgeComm
  • SetCommBreak
  • SetCommConfig
  • SetCommMask
  • SetCommState
  • SetCommTimeouts
  • SetDefaultCommConfig
  • SetupComm
  • TransmitCommChar
  • WaitCommEvent
For further details, consult the appropriate Microsoft documentation.

Can I create a redistributable library with ObjectAda without revealing my source code?
^ RETURN TO TOP ^
  ObjectAda is a source-based system and as such you have to redistribute a subset of your source in order for others to be able to compile Ada code that has any compile time dependencies on anything in your code. If such dependencies exist, you would need to ship:
  • Package specifications
  • Bodies of any generic packages that are available to be instantiated.
  • Bodies of packages to which Pragma Inline is applied.
Note that shipping bodies in the third case is optional. The compilation will succeed without them, but a warning will be issued and the code will be compiled as an out of line call.

The sources distributed with the runtime follow the above rules, and you can use the runtime library in %objectada%\lib\rts as an example of how to construct your delivery.

If you are delivering a product that will not be needed at compile time, for instance if you only offer object files needed at link time, i.e. built from sources to which pragma Export have been applied, you only need to ship the object files themselves. Such object files can be used individually, or in the form of an archive library build with the lib.exe tool included in your ObjectAda installation. Alternatively, if you're code is contained in a DLL, you can ship just the DLL and its associated import library that is created when the DLL is linked.

I don't understand what is meant by a "target" in a project. Does this mean that OAW can target applications to different processors or operating systems?
^ RETURN TO TOP ^
  "Target" is a terminology borrowed from Microsoft Visual C++, and simply refers to a collective set of options to be applied to a build. There is a one-to-one correspondence between targets and Ada libraries. By default, both a "release" and "debug" target are provided in a new project. The "release" target selects compile and link options for maximum performance, while the "debug" target selects options useful for debugging. Beyond these default targets, you can add any number of targets that you need from the Project -> Targets dialog window.

Does ObjectAda for Windows support task priorities?
^ RETURN TO TOP ^
  Yes. However, Windows 98/NT/2000 are not "real-time" operating systems, and Win32 supports only 7 levels of tasking priorities. Therefore, the 31 task priority levels required by Annex D are mapped many-to-one with Win32 threads. The user may modify the default mapping.

Where can I find sample programs to help me get started?
^ RETURN TO TOP ^
 

Many sample programs are included with the OAW CD-ROM. These samples may be found under %ObjectAda%\samples, where %ObjectAda% is the location of your ObjectAda installation. The %ObjectAda%\samples folder contains the following folders:

feldman  - samples from "Ada 95 Problem Solving and Program Design",
by Michael Feldman and Elliot Koffman (Addison Wesley Longman).  
java - Ada programs that can be compiled into Java byte code.
johnston - samples from "Ada 95 for C and C++ Programmers",
by Simon Johnston (Addison Wesley Longman).
ooprog - samples from the book "Object- Oriented Software in Ada 95" 
by Michael Smith (Thomson Computer Press).
w32ptzld  - samples from the book "Programming Windows 95"
by Charles Petzold.
win32ada  - samples of Windows programming using the Win32Ada bindings to the Win32 API.
graphics - samples of graphics plotting and drawing using the AdaPlot and AdaDraw libraries.
interrupt - interrupt processing programs (ObjectAda Real-Time only).


Can I modify the default mapping of Ada task priorities to Win32 thread priorities?
^ RETURN TO TOP ^
 

Yes. There are 31 priorities available to the Ada programmer. Under ETS ("ObjectAda Real-Time"), priorities 1..31 map directly to the ETS thread priorities -15..+15, but under Windows NT the only available priorities are:

Thread_Priority_Idle (-15)
Thread_Priority_Lowest (-2)
Thread_Priority_Below_Normal (-1)
Thread_Priority_Normal (0)
Thread_Priority_Above_Normal (+1)
Thread_Priority_Highest (+2)
Thread_Priority_Time_Critical (+15)

For a complete explanation of these priorities, see the Microsoft documentation. The following table describes the default mapping of Ada priorities to Windows NT priorities:

Ada Priorities NT Priorites
1..4 -15
5..8 -2
9..13 -1
14..17 0
18..22 +1
23..26 +2
27..31 +15

Because the mapping is many-to-one, it is possible that two tasks running at different Ada priorities may be mapped onto Windows NT threads executing at the same priority. If this is the case, the expected Ada semantics will not be observed; that is, the task of lower Ada priority may run in preference to that of higher priority. In this situation, you may choose to change the source code or to alter the priority mapping, which is represented as an array in the runtime and may be accessed in the following way:

type Priority_Map is array (System.Any_Priority) of Integer;

NT_Priority_Map : Priority_Map; -- initialized as above

pragma Import (C, NT_Priority_Map, "rts_nt_priority_map");

If the mapping array is altered dynamically, you must be careful to ensure that the array elements hold legal Windows NT priorities. The array must represent an appropriate mapping (there are no checks to this effect). You must also ensure that no tasks are elaborated prior to changing the mapping array.



What is the difference between a GUI Builder project and an OAW project?
^ RETURN TO TOP ^
  There is no relationship between a GUI Builder project and an ObjectAda project. However, the Ada 95 files and Windows resource files generated by the GUI Builder are among the types of files that would be added to an ObjectAda project in order to build the executable for a Windows application.

I'm trying to use Win32 common controls, but I get link errors. Why?
^ RETURN TO TOP ^
 

This probably means that there is a library that is not being passed to the linker. You need to identify any library that is needed to resolve symbols references in your code, but is not in the %objectada%\aplilib folder. (Libraries in %objectada%\apilib are passed to the linker by default.) Any such library should be added to the link type library search path found in Project -> Settings -> Search.

What if I want to statically link and make calls into Ada code from my C main program?
^
RETURN TO TOP ^
 

The following is an example of a C main program that calls into Ada code. Notice the Ada runtime initialization and finalization calls that are necessary to set up an Ada runtime environment prior to calling an Ada subprogram and destroy it upon returning to C. After the source code, you'll find a list of what you would need to link in from the Ada build environment in order to be able to build the C example program.

-- Begin code example

-- Ada package with subprograms you want to call from C
package ex_hello is
procedure hello;
pragma export (c, hello, link_name=>"_hello");
end ex_hello;

with text_io;
package body ex_hello is

procedure hello is
begin
text_io.put_line ("Hello World");
end hello;

end ex_hello;

-- Dummy main program that withs the packages containing
-- subprograms you want to be able to call
with ex_hello;
procedure with_hello is
begin
null;
end with_hello;

-- C code
extern adainit();
extern adafinal();
extern hello();

void main ()
{
adainit();
hello();
adafinal();
}

-- End code examples

-- Object files needed when linking the program
%Ada_project_directory_path%\%Ada_target%\obj\elt\with_hello.obj
%ObjectAda%\lib\crtpexe.obj
%ObjectAda%\lib\rts.lib
%ObjectAda%\lib\ntstub.lib
%ObjectAda%\lib\adamain.lib
%Ada_project_directory_path%\with_hello.compopts.obj
%Ada_project_directory_path%\obj\ada\ex_hello.obj



What is the best way to call Ada from C or C++?
^ RETURN TO TOP ^
 

In general, it is recommended that you build the code you're going to call as a DLL. For each data object or subprogram you intend to support, supply a pragma export of the form:

pragma Export(DLL, entity_name);

This will generate an entry in the .lib file that uses VC++ style name mangling and the cdecl calling convention. You can override the name used prior to mangling or the actual link name generated if you like, and you can also generate stdcall convention (for instance, if you want to dynamically load the DLL from visual basic).

The entities you wish to export should be declared in a package visible part, and a dummy "main" program of any name should include the packages you want in the DLL in its context clause.

In the project.settings.link tab, designate the application type as DLL.

When you now build, a main.exp, main.lib and main.dll file will be generated. If you're doing static linking from the C++ code to the DLL, include main.lib in the list of libaries to search at link time. This can be omitted if you're using loadLibrary to dynamically load the DLL.

The main of the DLL may be a dummy, but it actually serves to perform attach- time initialization of the DLL code (in addition to elaboration). Any user initialization code can be put there.

The "VC++ style" name mangling is not that associated with C++ functions (with the parameter and result types encoded in the link name) but rather that used for C - i.e. an underscore prefix (additional decoration is performed to create the names for the pointers through which the entities are accessed at runtime). The good news is that in general one doesn't have to worry about all this - simply match the 3rd (external_name) parameter of the pragma Import/Export to the corresponding C (or other language) entity name.



Can the GUI Builder produce an executable application from the application source code it generates?
^
RETURN TO TOP ^
  The GUI Builder does contain a basic Application Builder feature, however there are situations that require more control over the compile/link process than the Application Builder supports. For instance, an application may contain source files that were created outside the GUI Builder environment, or import library files that are not part of the ObjectAda runtime. In cases like that, it is more efficient to create an ObjectAda project to which all the files can be added. This also gives the user more freedom to easily choose among the various options and settings for the compile and link processes that are available in the ObjectAda IDE.

Does the GUI Builder support ActiveX controls?
^ RETURN TO TOP ^
  The GUI Builder does support adding ActiveX controls to the GUI application that is being designed. However, it may not be possible to fully manipulate and configure every control installed on your system inside the GUI Builder. This is due to a failure to retrieve a complete set of properties from the system registry in the case of some types of controls.

Can I use the OAW debugger to debug an Ada DLL?
^ RETURN TO TOP ^
  There is currently no support in the ObjectAda for Windows debugger for debugging Ada DLLs. However, if you've compiled the DLL with codeview information, you can you can use WinDBG, included in the ObjectAda for Windows product to do it. Or, if you have Microsoft Visual C++, you can use the debugger provided in the Visual Development Studio to debug the DLL.

Can I access network services from OAW?
^ RETURN TO TOP ^
  Win32Ada includes bindings for Winsock for network access protocols such as TCP/IP.

How can I use a CM tool with OAW?
^ RETURN TO TOP ^
  The ObjectAda IDE has an integrated CM menu based on the published Microsoft interface, SCCI. This menu provides direct access to typical CM operations (e.g., check-in and check-out), allowing you to plug into whichever SCCI compliant CM is installed on your system.

Can I use third-party editors with OAW?
^
RETURN TO TOP ^
  Yes, you can configure the IDE to use an alternative editor by selecting Tools -> Options -> Editor.

General
What is the proper usage of pragma Export?
^ RETURN TO TOP ^
 

pragma Export(C, entity_name);

is legal, but

pragma Export(C, entity_name, external_name);

is better practice. An example would be

procedure Foo;

pragma Export (C, Foo, "foo");

which does not leave the case of the subprogram name to chance.



How do I use the ObjectAda command line tools to script my application build?
^ RETURN TO TOP ^
  Following is an example of a DOS batch file that invokes the ObjectAda command line tools to build an application. Please note that virtually the same ObjectAda commmands could be used in a Unix shell script. Although the options are not exactly the same in the Unix hosted products as they are in the Windows hosted products, these minor variations can be resolved by executing any ObjectAda command with no options at the Unix command line. This will display a list of all the options that can be passed to the command, with a brief description of the purpose of each.

cmdline_batch_file_example
rem
rem **************************************


rem Set objectada for convenience
rem
set objectada=c:\program files\aonix\objectada

rem Add the bin directory to path so you can invoke executables easily
rem
set path=%path%;%objectada%\bin

rem Set up whatever environment variables you need.
rem For instance:
rem Location of your source files
rem
set srcpath="c:\sources"
set srcpath1="c:\more sources"
set srcpath2="c:\rest of sources"

rem Your working directory that will be the Ada libary
rem
set buildmaindir = "c:\buildmain"

rem Go to where you will create your new working library
rem and clean up existing library files
rem
cd %buildmaindir%
del unit.map /q
del ada.lib /q
rd xref /q /s
rd obj /q /s
rd il /q /s
rd msg /q /s
rd info /q /s
rem
rem **************************************

rem Create your Ada library and insert necessary Ada libraries into
rem your search path.
rem The Ada runtime library is automatically inserted.
rem Alternatively, you can create an ADAOPTS.SS file with this
rem info in it for adaopts to use.
rem Check out the online help for details.
rem
rem **************************************

adaopts -pi 0 %objectada%\bsp\system\
adaopts -pi 0 %objectada%\bsp\RAVEN\
adaopts -pi 0 %objectada%\extensions


rem Register all your program source files
rem
adareg %srcpath%\*.a*
adareg %srcpath1%\*.a*
adareg %srcpath2%\*.a*

rem Compile source files
rem
rem adacomp %srcpath%\*.a*
rem adarcomp %srcpath1%\*.a*
rem adacomp %srcpath2%\*.a*

rem Build the program
rem
adabuild

rem **************************************

rem To get a list of available options for any ObjectAda command,
rem type the name of the command at the DOS prompt, then press enter.
rem
rem **************************************



Tools
Is a profiler available?
^ RETURN TO TOP ^
  The ASIS based ObjectAda AdaNav toolset includes a profiler.

The debugger "step" command is "grayed-out" unless the debugger is already running. How can I step to the first executable instruction without setting a breakpoint first?
^ RETURN TO TOP ^
  Clicking on the "Restart" button will initiate the debugger and place the cursor at the first executable Ada instruction.

How do I examine package global data items that are not in the same package as the location of the current breakpoint?
^ RETURN TO TOP ^
  To access out-of-scope data, use the fully-qualified name of the data item.

ObjectAda Real-Time
How precise is the system timer and does it depend on the CPU speed?
^ RETURN TO TOP ^
  Timer precision is independent of the CPU speed - it's programmed via the 8254 PIT or similar device. The provided ETS kernel driver supports precisions set in the range 1-55ms. in 1 ms increments. If you have, or plan to develop, a kernel driver that supports a finer resolution, you can use it in place of the one that's provided.

Does ObjectAda ETS provide graphical timing analysis?
^ RETURN TO TOP ^
  No, but ETS (starting in ETS 9.0) has system calls that can be used to instrument code to collect such data.

Are there ways to lock memory to control paging? For instance, can I lock a 40meg chunk of data into memory to prevent it being swapped out?
^ RETURN TO TOP ^
  ETS is a non-paged system. There is no virtual memory management, but the processor executes in protected mode.