0

I've been trying different things all weekend trying to figure out what is going on here.

If I log in to my server via a PC and telnet, it comes through just fine. So I know it's my code here is messed up.

Here's my code

while(1)
	{
		mbstowcs(CHAT," ",strlen(" ")-1 );
		Edit_SetText(ctrlCHATLOG, CHAT);
		int receivedNumber = recv(lpSocket, szRecvBuffer, DEFAULT_BUFLEN-1, 0);
		if(receivedNumber ==-1)
		{
			break;
		}
		szRecvBuffer[receivedNumber-1] ='\0';
		mbstowcs(CHAT,szRecvBuffer,strlen(szRecvBuffer)-1 );
		Edit_SetText(ctrlCHATLOG, CHAT);
	}

This is for a textbox on a Pocket PC app.

Lets say my first packet is
"abcdefg"
that will show up fine in my text box.

Then lets say my 2nd packet is
"123"

What shows up is "123defg"

I cant figure out why. I've tried multiple things.

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by kireol
0

>>mbstowcs(CHAT," ",strlen(" ")-1 );
That's the same as this: mbstowcs(CHAT," ",0); . In otherwords, it does nothing.

>>What shows up is "123defg"
You aren't clearing the CHAT beffer before copying the contents of szRecvBuffer. Zero it out first. The second problem is that you are subtracting 1 from the length of the szRecvBuffer which is truncating the last character.

memset(CHAT, 0, sizeof(CHAT));
mbstowcs(CHAT,szRecvBuffer,strlen(szRecvBuffer) );
Edit_SetText(ctrlCHATLOG, CHAT);
0

that was it. thanks sir. I assumed the terminated string that I was copying into the TCHAR would be sufficient. Easy fix though. thanks again. I owe you a beer ;)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.