Solved

Converting wvsprintf() to 32 bit

Posted on 1997-10-20
13
836 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
This video discusses moving either the default database or any database to a new volume.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now