Solved

Converting wvsprintf() to 32 bit

Posted on 1997-10-20
13
870 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

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…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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