From: EMANUELE COSTA <costa@UNIX.LANCS.AC.UK>
Subject: Wvsprintf in Ada
Date: 1996/04/09
Date: 1996-04-09T00:00:00+00:00 [thread overview]
Message-ID: <Pine.SOL.3.91.960409172122.6416A-100000@unixb.lancs.ac.uk> (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
======================
next reply other threads:[~1996-04-09 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-04-09 0:00 EMANUELE COSTA [this message]
1996-04-12 0:00 ` Wvsprintf in Ada Mitch Gart
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox