Solved

Converting wvsprintf() to 32 bit

Posted on 1997-10-20
13
851 Views
Last Modified: 2013-12-03
The following is some sample code that I have in 16 bit.
{
int vArgs[4];
vArgs[0] = OFFSETOF((LPSTR)szString);
vArgs[1] = SELECTOROF((LPSTR)szString);
vArgs[2] = LOWORD(someLong);
vArgs[3] = HIWORD(someLong);
wvsprintf((LPSTR)szNote, StrGetFormat(MSG_NUMBERX), &vArgs);
}
Whilst trying to port my code to 32 bit I'm getting a load of compilier warnings which I can't seem to resolve. The third arguement to wvsprint is a va_list type and I can't seem to figure out how to use it correctly. Any help is greatly appreciated.
0
Comment
Question by:kiml
  • 3
  • 3
  • 2
  • +3
13 Comments
 
LVL 4

Expert Comment

by:davmarc
ID: 1407694
32-bit wvsprintf() works pretty differently and is very similar to sprintf(). No need to deal with offsets and selectors anymore.

This is what VC++ 5.0 documentation says about the parameters in input:


lpOutput
Points to a buffer to receive the formatted output.

lpFormat
Points to a null-terminated string that contains the format-control specifications. In addition to ordinary ASCII characters, a format specification for each argument appears in this string. For more information about the format specification, see the wsprintf function.

arglist
A variable argument list; each element of the list specifies an argument for the format-control string. The number, type, and interpretation of the arguments depend on the corresponding format-control specifications in the lpFmt parameter.


Davide Marcato.
0
 

Author Comment

by:kiml
ID: 1407695
Davmarc,
Yeah I had got through reading the manual but I still couldn't figure out how to port the code. I had tried something like:
va_list vArgs[2];
vArgs[0] = szString;
vArgs[1] = &someLong;
wvsprintf(abuf, aformat, vArgs);
but the compiler complained about vArgs, I tried &vArgs as well to no avail. Any ideas on actually porting the code or do I just ignore the warnings?, or is there some other way to setup vArgs?.
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1407696
You could try something like this:

 int intlist[2];

 intlist[0] = (int)szString;
 intlist[1] = (int)someLong;

 va_list vArgs;
 va_start(vArgs, intlist[0] );
 
 wvsprintf(abuf, aformat, vArgs);

 va_end(vArgs);

0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 7

Expert Comment

by:faster
ID: 1407697
You can simply use:

wvsprintf(abuf, aformat, szString, someLong);  Provided that it is what you want and the aformat is correct.
0
 
LVL 7

Expert Comment

by:faster
ID: 1407698
wvsprintf is just like wsprintf or printf, suppose you want to write a string and a number to the buffer, you can use:

wsprintf(buf, "%s %d", pszString, nInt);

The "%s %d" can be replaced with a buffer which contains the similar format string of course.

If you still have problem, please tell me what do you exactly want in the buffer.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1407699
The following example code has been tested. You'd better reject faster's answer and accept mine.

TCHAR achBuf[32];
LPCTSTR lpszFormat = _T("%s   %ld   %c   %d");

LPCTSTR lpszStr = _T("string");
LONG lNum1 = 123456;
TCHAR chChar = _T('u');
int nNum2 = -987;

int pnParams[5];
pnParams[0] = 0;               // virtual parameter
pnParams[1] = (int)lpszStr;    // 1st parameter
pnParams[2] = (int)lNum1;      // 2nd parameter
pnParams[3] = (int)chChar;     // 3rd parameter
pnParams[4] = (int)nNum2;      // 4th parameter
      
va_list argList;
va_start(argList, pnParams[0]);
      
wvsprintf(achBuf, lpszFormat, argList);
      
va_end(argList);

0
 

Author Comment

by:kiml
ID: 1407700
Looks like Chensu and y96andha agree on the approach to take. I need to test out their code and get back to you all. BTW who do I  give the points to since y96andha gave the correct answer but Chensu perhaps is more correct?.
0
 

Expert Comment

by:kw040597
ID: 1407701
y96andha's answer was just the correct answer, I DON'T think anyone could be MORE correct.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1407702
kw:
Have you tried the code? Note the 2nd parameter of va_start must be the previous one prior to the actual parameters.
0
 

Expert Comment

by:kw040597
ID: 1407703
chensu,
I appologize to you. I just missed this point, now I recalled one has to push the format string first and then the following onto stack and pass the address of the format string to va_start. If you save lpszStr into pnParams[0], I would have recalled this quicker.
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1407704
chensu has the answer, mine was just a guess. I would have found it if I tried the code, but I figured someone (like chensu) had already done that, and could provide an answer.
0
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 1407705
TCHAR achBuf[32];
LPCTSTR lpszFormat = _T("%s %ld %c %d");

LPCTSTR lpszStr = _T("string");
LONG lNum1 = 123456;
TCHAR chChar = _T('u');
int nNum2 = -987;

int pnParams[5];
pnParams[0] = 0; // virtual parameter
pnParams[1] = (int)lpszStr; // 1st parameter
pnParams[2] = (int)lNum1; // 2nd parameter
pnParams[3] = (int)chChar; // 3rd parameter
pnParams[4] = (int)nNum2; // 4th parameter

va_list argList;
va_start(argList, pnParams[0]);

wvsprintf(achBuf, lpszFormat, argList);

va_end(argList);


Thank you.
0
 

Author Comment

by:kiml
ID: 1407706
Thanks to everyone for their input
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question