Author | Message | Time |
---|---|---|
Spilled[DW] | Ok first off i was trying to port my vb dataarrival to C++ but this is my first time doing this and would like your guys help/advice. Heres what i have so far: [code] DWORD WINAPI ThreadProc(LPVOID lpParameter) { if ((int)lpParameter == RECV_DATA) { while (sRet != SOCKET_ERROR) { sRet = recv(wSock,rData,256,0); if (sRet != SOCKET_ERROR) { char recBuff[sRet]; char strBuffer[800]; int lngLen; CopyMemory(strBuffer+strlen(strBuffer), recBuff, sRet); while (strlen(strBuffer) > 4) { lngLen = (int) StrToHex(StringReverse(Mid(recBuff, 3, 2))); if (strlen(strBuffer) < (int) lngLen) { break; } else { //would parsep (Left(strBuffer, lngLen)) } } } } } } [/code] Any ideas why its not working? Thanks in advance! | September 23, 2005, 11:42 PM |
UserLoser. | uhh, where's sRet declared? why are you using strlen()? StrToHex(), StringReverse()? Why would you even do that in VB? Try something like: "lngLen = *(uint16*)(recBuff+2);" Probably better to do: "while(recv(whatever) != SOCKET_ERROR) { ... }", no? Wouldn't "break;" cause your thread to die? That's no good. Shouldn't you be waiting on an event before you do recv()? Otherwise it'll return SOCKET_ERROR because there's nothing to recieve... Ok, let me say it in English: don't convert VB to C++ | September 24, 2005, 1:20 AM |
Spilled[DW] | wow... thats alot of problems... like ive said tho still learning c++. Can you help me with writing this or even give me a start? Edit: So i would do the loop more like: [code] DWORD WINAPI ThreadProc(LPVOID lpParameter) { if ((int)lpParameter == RECV_DATA) { while (recv(wSock,rData,256,0) != SOCKET_ERROR) { } } } [/code] ? - Kinda lost here. All advice is appreciated. | September 24, 2005, 2:13 AM |
Imperceptus | Seach Google for C++ Tutorials, Im using this [url]http://www.cprogramming.com/tutorial.html#c++tutorial[/url] Also suggest MSDN Learn the Basics, if your just trying to match keywords and functions that were done in vb then you will really have issues. Sit down and Read, A LOT. Theres alot to take in. Read an Article on C++ and VB, which breaks it down like this. VB is RAD (Rapid App Dev), C++ is planned thought out programming. If you can't figure out the childish fingerpaintings of C++ how do you expect to understand more complex topics? | September 25, 2005, 12:26 PM |
Spilled[DW] | [quote author=UserLoser link=topic=12890.msg129139#msg129139 date=1127524853] uhh, where's sRet declared? why are you using strlen()? StrToHex(), StringReverse()? Why would you even do that in VB? Try something like: "lngLen = *(uint16*)(recBuff+2);" Probably better to do: "while(recv(whatever) != SOCKET_ERROR) { ... }", no? Wouldn't "break;" cause your thread to die? That's no good. Shouldn't you be waiting on an event before you do recv()? Otherwise it'll return SOCKET_ERROR because there's nothing to recieve... Ok, let me say it in English: don't convert VB to C++ [/quote] Ok, going threw what you reponded with ive tried the "lngLen = *(unit16*)(recBuff+2);" it keeps saying unit16 is undeclared. Ive looked up UINT and it says i need windows.h header file and i have that included. So some help here? Thanks in advance! Edit: After working a few more hours, heres what i have come up with: [code] DWORD WINAPI ThreadProc(LPVOID lpParameter) { if ((int) lpParameter == RECV_DATA) { char buffer[256]; int iret; int count = 0; while(iret != SOCKET_ERROR) { iret = recv(wSock,buffer,256,0); if (iret == SOCKET_ERROR) { int we = WSAGetLastError(); switch(we) { case 10054: cout << "Conenction Reset by Peer..." << endl; break; default: cout << we << endl; break; } } else { int bufflen = iret; while(bufflen >= 4) { //char PacketID = (unsigned char)buffer+1; unsigned short uPacketLen = *(unsigned short *)(buffer+2); cout << "Packet Len: " << uPacketLen << endl; // just to see the len Parsep(buffer, uPacketLen); memmove(buffer, buffer+uPacketLen, bufflen-uPacketLen); bufflen -= uPacketLen; } ZeroMemory(buffer,iret); } } } } [/code] Any ideas are appreciated! No flaming please trying to learn! Thanks in advance everyone. | September 26, 2005, 7:50 AM |