Click here to Skip to main content
15,898,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: initializing code for a New Dialog Box Pin
Nibu babu thomas1-Jan-09 20:08
Nibu babu thomas1-Jan-09 20:08 
QuestionWorking wiht MFC Dialog Pin
Member 36811811-Jan-09 19:21
Member 36811811-Jan-09 19:21 
AnswerRe: Working wiht MFC Dialog Pin
CPallini1-Jan-09 20:04
mveCPallini1-Jan-09 20:04 
QuestionCompile time errors Pin
Aabid1-Jan-09 19:17
Aabid1-Jan-09 19:17 
AnswerRe: Compile time errors Pin
Hamid_RT1-Jan-09 20:11
Hamid_RT1-Jan-09 20:11 
AnswerRe: Compile time errors Pin
PCuong19831-Jan-09 21:25
professionalPCuong19831-Jan-09 21:25 
Questionsprintf? Pin
dec821-Jan-09 18:45
dec821-Jan-09 18:45 
AnswerRe: sprintf? Pin
Nibu babu thomas1-Jan-09 18:58
Nibu babu thomas1-Jan-09 18:58 
hung1984 wrote:
if (ptrList [i])
sprintf(ss, "%s", *(CString *) ptrList [i]);


From the code...

ptrList is an array of CString pointers which for some reason is kept as void pointers, but the developer knows it's internally CString* so he is "confidently" casting it to CString* then copying the CString value to a character buffer (ss).

Confusing at times and also he forgot another step to cast *(CString*) to LPCTSTR and to use _stprintf instead of sprintf.

So after correction the code will look like...

void *ptrList [30];
char ss [40];
for (i = 0; i<26; i++)
{
  if (ptrList [i])
  {
    LPCTSTR lpctszStr = (LPCTSTR)(*(CString *) ptrList [i]);
    _stprintf(ss, "%s", lpctszStr);
  }
}



Nibu babu thomas
Microsoft MVP for VC++


Code must be written to be read, not by the compiler, but by another human being.

Programming Blog: http://nibuthomas.wordpress.com

AnswerRe: sprintf? Pin
ThatsAlok1-Jan-09 19:02
ThatsAlok1-Jan-09 19:02 
AnswerRe: sprintf? Pin
dec821-Jan-09 21:10
dec821-Jan-09 21:10 
GeneralRe: sprintf? Pin
PCuong19831-Jan-09 21:56
professionalPCuong19831-Jan-09 21:56 
QuestionRe: sprintf? Pin
David Crow2-Jan-09 4:01
David Crow2-Jan-09 4:01 
AnswerRe: sprintf? Pin
Stephen Hewitt3-Jan-09 22:05
Stephen Hewitt3-Jan-09 22:05 
QuestionProblem in Fit to Page Width Printing. Pin
Le@rner1-Jan-09 18:39
Le@rner1-Jan-09 18:39 
AnswerRe: Problem in Fit to Page Width Printing. Pin
Hamid_RT1-Jan-09 20:17
Hamid_RT1-Jan-09 20:17 
GeneralRe: Problem in Fit to Page Width Printing. Pin
Le@rner1-Jan-09 20:22
Le@rner1-Jan-09 20:22 
GeneralRe: Problem in Fit to Page Width Printing. Pin
Hamid_RT1-Jan-09 20:55
Hamid_RT1-Jan-09 20:55 
GeneralRe: Problem in Fit to Page Width Printing. Pin
Le@rner1-Jan-09 22:32
Le@rner1-Jan-09 22:32 
QuestionThe program reads and writes hard disk in a thread heavily, how to make it work when idle? Pin
followait1-Jan-09 18:07
followait1-Jan-09 18:07 
AnswerRe: The program reads and writes hard disk in a thread heavily, how to make it work when idle? Pin
Jijo.Raj1-Jan-09 23:57
Jijo.Raj1-Jan-09 23:57 
QuestionMultithreading Pin
hrishiS1-Jan-09 18:00
hrishiS1-Jan-09 18:00 
AnswerRe: Multithreading Pin
Hamid_RT1-Jan-09 18:09
Hamid_RT1-Jan-09 18:09 
GeneralRe: Multithreading Pin
hrishiS1-Jan-09 18:18
hrishiS1-Jan-09 18:18 
GeneralRe: Multithreading Pin
hrishiS1-Jan-09 18:30
hrishiS1-Jan-09 18:30 
AnswerRe: Multithreading Pin
Roger Stoltz1-Jan-09 22:17
Roger Stoltz1-Jan-09 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.