Converting wvsprintf() to 32 bit

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.
kimlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

davmarcCommented:
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
kimlAuthor Commented:
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
y96andhaCommented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

fasterCommented:
You can simply use:

wvsprintf(abuf, aformat, szString, someLong);  Provided that it is what you want and the aformat is correct.
0
fasterCommented:
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
chensuCommented:
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
kimlAuthor Commented:
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
kw040597Commented:
y96andha's answer was just the correct answer, I DON'T think anyone could be MORE correct.
0
chensuCommented:
kw:
Have you tried the code? Note the 2nd parameter of va_start must be the previous one prior to the actual parameters.
0
kw040597Commented:
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
y96andhaCommented:
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
chensuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kimlAuthor Commented:
Thanks to everyone for their input
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.