* Wvsprintf in Ada
@ 1996-04-09 0:00 EMANUELE COSTA
1996-04-12 0:00 ` Mitch Gart
0 siblings, 1 reply; 2+ messages in thread
From: EMANUELE COSTA @ 1996-04-09 0:00 UTC (permalink / raw)
Hello everybody,
I'm trying to convert the programs which appear in the book
"Programming Windows" by Peztold from C to Ada, and I've encountered a
curious problem with the use of the Win32 api function Wvsprintf.
Actually the function is supported within the Alsys Activada
compiler throughout the call to the pragma CALL_IN, but it doesn't seem
to work in the same way as the C function does.
Here is an example:
if we had the following code in C:
short nLength;
char szBuffer[40];
nLength = wvsprintf(szBuffer,"The sum of %d and %d is %d",
nA,nB,nA+nB);
Textout(hdc,x,y,szBuffer,nLength);
and we wrote down the following Ada code:
nLength : integer;
szBuffer1 : string(1..100);
szBuffer2 : constant string := "The sum of %d and %d is %d" &
ascii.null;
nLength:=wvsprintf(szBuffer1'address,szBuffer2'address,nA,nB,nA+nB);
Textout(hdc,x,y,szBuffer1,nLength);
we 'll finished with this compiling time error:
No Valid prefix is compatible with this list of indexes or of
parameters.
The unique solution I've worked out so far is to declare an array to
store all the integers I need to perform the sum, and assuming that all the
numbers will be stored in adjacent memory locations we have got the
following code:
nLength : integer;
szBuffer1 : string(1..100);
szBuffer2 : constant string := "The sum of %d and %d is %d" &
ascii.null;
type number is array (1..3) of integers;
sum_numbers : number;
sum_numbers(1) := 2;
sum_numbers(2) := 3;
sum_numbers(3) := sum_numbers(1) + sum_numbers(2);
nLength:=wvsprintf(szBuffer1'address,szBuffer2'address,sum_numbers'
address);
Textout(hdc,x,y,szBuffer1,nLength);
and peculiarly enough the program seems to work fine and at the end a
window is displayed on the screen with the correct output.
The only thing is that the whole procedure looks quite
clumsy, so I would like to know if there is someone who can help me and
perhaps suggest a better solution to this problem.
Thanks a lot
EMANUELE COSTA
======================
Emanuele Costa
Pendle College
Lancaster University
costa@unix.lancs.ac.uk
======================
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Wvsprintf in Ada
1996-04-09 0:00 Wvsprintf in Ada EMANUELE COSTA
@ 1996-04-12 0:00 ` Mitch Gart
0 siblings, 0 replies; 2+ messages in thread
From: Mitch Gart @ 1996-04-12 0:00 UTC (permalink / raw)
In the Win32Ada binding available at
http://sw-eng.falls-church.va.us/AdaIC/source-code/bindings/
the binding to this function is
function wvsprintf(lpOut : Win32.LPSTR;
lpFmt : Win32.LPCSTR;
arglist: Stdarg.ArgList := Stdarg.Empty)
The key to it is the Stdarg package which handles variable-length
argument lists, and which is included as part of the binding.
The binding is Ada 95. Hope that helps.
- Mitch Gart
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-04-12 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-09 0:00 Wvsprintf in Ada EMANUELE COSTA
1996-04-12 0:00 ` Mitch Gart
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox