Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jul 10th, 2005, 1:17 PM   #1
hbweb500
Newbie
 
Join Date: Jul 2005
Posts: 4
Rep Power: 0 hbweb500 is on a distinguished road
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
hbweb500 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:59 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC