tags:

views:

156

answers:

1

I would like to now how to pass a standard Boolean Type in Ada through the Interfaces.C package in order to call a DLL function. The Interfaces.C package does not contain the Ada Boolean type since the boolean type does not exist in ANSI C. I have a DLL function written in C++ whose exported function prototype has an argument of type Bool. How is this passed in the Intefaces.C package in order to call the DLL exported function?

+4  A: 

traditionally, in C, a boolean is represented with an int type. in C++, a bool type is defined, but note the lowercase 'b'. if your argument is of type Bool (note the uppercase 'B') then you should have a class declaration somewhere (in your C++ library) which will tell you more about the implementation of the type. generally, such a Bool class is made compatible with a standard bool type through some artifact of the language: the Bool class defines no virtual function and keeps its value in a member judiciously placed first in the definition of the class.

i did not test it, but i would say you can go with an int type. make a test to be sure it is accepted by the C++ function. for converting from Boolean to int, you may use something like Interfaces.C.int(Boolean'Pos(your_bool_value)).

also note that, as specified in the Ada Reference Manual [B.3.62]: An implementation may provide additional declarations in the C interface packages. so check your implementation of Interfaces.C, it may contain a definition for a bool type.

Adrien Plisson
I don't know about `Bool`, but `BOOL` is typedef'ed in WinDef.h on my system as `int`
T.E.D.