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.

Recommended Answers

All 2 Replies

>>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);

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 ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.