Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 894
  • Last Modified:

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.
0
kiml
Asked:
kiml
  • 3
  • 3
  • 2
  • +3
1 Solution
 
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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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
 
kimlAuthor Commented:
Thanks to everyone for their input
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now