PDA

Click to See Complete Forum and Search --> : SendMessage(error with integers)


SteveCRM
Mar 3rd, 2001, 04:03 PM
I keep getting pretty bad errors on this...like protection faults.

here is the code in my button:


int thenumber;
char * pc;
itoa(thenumber, pc, thenumber);

srand(time(NULL));
num1 = 1 + rand() % 3;
num2 = 1 + rand() % 3;
num3 = 1 + rand() % 3;

SendMessage(ghWnd_Slot1, WM_SETTEXT, 0, (LPARAM) (LPCTSTR) itoa(num1, pc, 10));
SendMessage(ghWnd_Slot2, WM_SETTEXT, 0, (LPARAM) (LPCTSTR) itoa(num2, pc, 10));
SendMessage(ghWnd_Slot3, WM_SETTEXT, 0, (LPARAM) (LPCTSTR) itoa(num3, pc, 10));

parksie
Mar 3rd, 2001, 04:08 PM
It's the way you used itoa. You need to have a buffer of a sufficient size - I normally use 40 characters:

char buf[40];
int x = 5;

itoa(x, buf, 10); // 10 is the radix (number base)

Also, don't use LPCTSTR unless you're willing to use Unicode :(. Just use plain LPCSTR. And since casting just converts it around you don't need it and can stay with LPARAM.

SteveCRM
Mar 3rd, 2001, 04:51 PM
As usual, it works after help from parksie :D

thanks again




and for anyone that's interrested, I attached what I made. :)

SteveCRM
Mar 3rd, 2001, 04:56 PM
Oh by the way, I meant to ask you something. I noticed that it doesn't change the numbers sometimes, but the cash does change (I think you'll have to download the attachment to know what I'm talking about)....its in the button named ghWnd_Pull