Problem With sprintf and LPCTSTR?

This is a discussion on Problem With sprintf and LPCTSTR? within the Windows Programming forums, part of the Platform Specific Boards category; Actually, I'm not sure what my problem is. I'm trying to change the text of a Resource Dialog Box field ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    Problem With sprintf and LPCTSTR?

    Actually, I'm not sure what my problem is. I'm trying to change the text of a Resource Dialog Box field to a number. My code compiles okay, but when it runs this segment of code always causes the program to crash. (It is run 60 times) The Error it gives me when the program crashes says "Stack Around The Variable 'message' Has Been Corrupted" Help, please....

    Code:
    char message[2];
    sprintf(message, "%d", currentSecondsCount);
    SetDlgItemText(hWndNew, IDC_TIMERTEXT, (LPCTSTR)message);
    Last edited by ElWhapo; 04-23-2005 at 11:30 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    your problem is that your message buffer is only 2 chars in length, when you consider the NULL terminating charactor added by sprintf there is realy only 1 char to place output in.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    ahah! thanks

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21