|
Newbie
Join Date: Jul 2005
Posts: 4
Rep Power: 0 
|
Return Strings in Function
In the Win32 program I am writing, I refer to different building names by integers so I can store information in arrays. Whenever I need to output this information, however, I need to associate a string with the integer so as the user will actually know what building I am talking about. I made a function to do this.
The first problem is using WSPRINTF().
LPTSTR string;
wsprintf(temp, "%hS","Research Lab");
The above code will compile but not run, as I get a "Cannot Write to Memory" error when I reach this section of the program.
To counter this, I follow MSDN's example. There they use a TCHAR. The problem is, I cant seem to find a way to get the function to return a TCHAR to the program, and get it to work.
Here is the function:
VOID NameBuilding(int bldng, TCHAR *bldngname)
{
TCHAR temp[80];
switch(bldng)
{
case 0:
wsprintf(temp, "%S","Metal Mine");
break;
case 1:
wsprintf(temp, "%S","Crystal Mine");
break;
case 2:
wsprintf(temp, "%S","Deuterium Mine");
break;
case 3:
wsprintf(temp, "%S","Solar Plant");
break;
case 4:
wsprintf(temp, "%S","Robotic Plant");
break;
case 5:
wsprintf(temp, "%S","Shipyard");
break;
case 6:
wsprintf(temp, "%S","Metal Storage");
break;
case 7:
wsprintf(temp, "%S","Crystal Storage");
break;
case 8:
wsprintf(temp, "%S","Deuterium Tank");
break;
case 9:
wsprintf(temp, "%S","Research Lab");
break;
case 10:
wsprintf(temp, "%S","Rocket Silo");
break;
}
// Now here I have tried using the pointer I called for, bldngname, to write directly to the var, but no luck. I have also tried making the temp var a LPSTR and returning it, but it wont work with the WSPRINTF then.
}
And here is what I need to do witht that output:
TCHAR string[80];
wsprintf(string,"%hS",temp);
//where temp is the returned string
I am thinking that the returned data must be a LPSTR or the like, but I just cant seem to figure this out.
Thanks,
Jeffrey
|