Click here to Skip to main content
15,907,874 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Error Message Pin
Stephen Hewitt1-Oct-07 19:37
Stephen Hewitt1-Oct-07 19:37 
QuestionRe: Error Message Pin
David Crow2-Oct-07 2:28
David Crow2-Oct-07 2:28 
AnswerRe: Error Message Pin
Cedric Moonen1-Oct-07 20:58
Cedric Moonen1-Oct-07 20:58 
QuestionHow to read bytes from winsock efficiently Pin
Ontanggabe Parulian1-Oct-07 17:20
Ontanggabe Parulian1-Oct-07 17:20 
AnswerRe: How to read bytes from winsock efficiently Pin
chandu0041-Oct-07 19:27
chandu0041-Oct-07 19:27 
QuestionRe: How to read bytes from winsock efficiently Pin
Ontanggabe Parulian1-Oct-07 19:41
Ontanggabe Parulian1-Oct-07 19:41 
AnswerRe: How to read bytes from winsock efficiently Pin
chandu0041-Oct-07 19:48
chandu0041-Oct-07 19:48 
GeneralRe: (Revision)How to read bytes from winsock efficiently Pin
Ontanggabe Parulian1-Oct-07 20:17
Ontanggabe Parulian1-Oct-07 20:17 
Sory, here I repost the source code again cause the previous is not complete. The source code here is modified from the previous so you can run it on your machine. The certain variables here I initialized so it meet the testing environment that I used.

void main()<br />
{<br />
int ld_intByteRqLen;<br />
<br />
// ld_strCompIsoMsg is the actual message<br />
string ld_strCompIsoMsg("600015800002003020058020C010040010000000000333000002500021001500325577911013392824D12041011646435036343333373730313030303030303039323739393435357556C9933721414F0006303030333539");<br />
ld_intByteRqLen = ld_strCompIsoMsg.length() >> 1;<br />
<br />
char *ld_pchrByteRq = new char[ld_intByteRqLen];<br />
for(int i=0; i < ld_intByteRqLen; ld_pchrByteRq[i++]=0);<br />
<br />
// Convert the actual message to Byte<br />
this->mfc_voidHex2Byte((char*)this->md_strCompIsoMsg.c_str(), ld_pchrByteRq, 0, ld_intByteRqLen);<br />
<br />
// ld_intTCPByteRqLen added by 2 caused the first two bytes contain the message length<br />
int ld_intTCPByteRqLen = ld_intByteRqLen + 2;<br />
<br />
// ld_pchrTCPByteRq is the final message that will be passed through the network<br />
char *ld_pchrTCPByteRq = new char[ld_intTCPByteRqLen];<br />
<br />
// Here the algorithm of how the first two bytes save the message length<br />
if(ld_intByteRqLen <= 255)<br />
{<br />
ld_pchrTCPByteRq[0] = 0;<br />
ld_pchrTCPByteRq[1] = ld_intByteRqLen;<br />
}<br />
else<br />
{<br />
ld_pchrTCPByteRq[0] = ld_intByteRqLen / 256;<br />
ld_pchrTCPByteRq[1] = ld_intByteRqLen % 256;<br />
}<br />
<br />
// I concatenate the ld_pchrByteRq to the ld_pchrTCPByteRq<br />
// Using looping cause I can't use strcat while the string value contain NULL<br />
for(int i=2, j=0; i < ld_intTCPByteRqLen; i++, j++)<br />
{<br />
ld_pchrTCPByteRq[i] = ld_pchrByteRq[j];<br />
}<br />
<br />
// The TCPByteRq is the message that will be passed through the network<br />
// Here I printed its contain using loop for ant type cast to int (cause it can contain NULL)<br />
for(int i=0; i < ld_intTCPByteRqLen; i++) cout << "ld_pchrTCPByteRq[" << i << "] = " << (int)ld_pchrTCPByteRq[i] << endl;<br />
<br />
delete [] ld_pchrByteRq;<br />
delete [] ld_pchrTCPByteRq;<br />
}<br />
<br />
void mfc_voidHex2Byte(char *ld_pchrScr, char *ld_pchrDest, int ld_intStartOffset,int ld_intLen)<br />
{<br />
char ld_chrBuf1[2], *ld_pchrBuf2;<br />
ld_chrBuf1[1]=0;<br />
int ld_intShiftLeft;<br />
for(int i=0; i < (ld_intLen * 2); i++)<br />
{<br />
if(i%2 == 1) ld_intShiftLeft = 0; <br />
else ld_intShiftLeft = 4;<br />
ld_chrBuf1[0] = ld_pchrScr[ld_intStartOffset+i];<br />
ld_pchrDest[i>>1] = ld_pchrDest[i>>1] | strtol(ld_chrBuf1,&ld_pchrBuf2,16) << ld_intShiftLeft;<br />
}<br />
} 


Ian
QuestionRe: How to read bytes from winsock efficiently Pin
David Crow2-Oct-07 2:30
David Crow2-Oct-07 2:30 
Questionobviously 0xffff, i.e 65535. Pin
chandu0042-Oct-07 2:38
chandu0042-Oct-07 2:38 
AnswerRe: How to read bytes from winsock efficiently Pin
David Crow2-Oct-07 2:41
David Crow2-Oct-07 2:41 
GeneralRe: How to read bytes from winsock efficiently Pin
chandu0042-Oct-07 2:45
chandu0042-Oct-07 2:45 
AnswerRe: How to read bytes from winsock efficiently Pin
Mark Salsbery1-Oct-07 20:10
Mark Salsbery1-Oct-07 20:10 
AnswerRe: How to read bytes from winsock efficiently (Problem SOLVED) Pin
Ontanggabe Parulian1-Oct-07 20:44
Ontanggabe Parulian1-Oct-07 20:44 
GeneralRe: How to read bytes from winsock efficiently (Problem SOLVED) Pin
Mark Salsbery2-Oct-07 5:04
Mark Salsbery2-Oct-07 5:04 
JokeRe: How to read bytes from winsock efficiently Pin
Moak9-Nov-07 1:25
Moak9-Nov-07 1:25 
QuestionAnyone know how to make something "auto-hide" ? Pin
USAFHokie801-Oct-07 14:07
USAFHokie801-Oct-07 14:07 
AnswerRe: Anyone know how to make something "auto-hide" ? Pin
Hamid_RT1-Oct-07 19:35
Hamid_RT1-Oct-07 19:35 
AnswerRe: Anyone know how to make something "auto-hide" ? Pin
Nelek1-Oct-07 21:42
protectorNelek1-Oct-07 21:42 
QuestionRe: Anyone know how to make something "auto-hide" ? Pin
David Crow2-Oct-07 2:34
David Crow2-Oct-07 2:34 
AnswerRe: Anyone know how to make something "auto-hide" ? Pin
USAFHokie802-Oct-07 12:19
USAFHokie802-Oct-07 12:19 
QuestionFlicker free painting with PNG images Pin
Leslie Sanford1-Oct-07 11:04
Leslie Sanford1-Oct-07 11:04 
AnswerRe: Flicker free painting with PNG images Pin
Mark Salsbery1-Oct-07 12:07
Mark Salsbery1-Oct-07 12:07 
GeneralRe: Flicker free painting with PNG images [modified][solved] Pin
Leslie Sanford1-Oct-07 12:51
Leslie Sanford1-Oct-07 12:51 
GeneralRe: Flicker free painting with PNG images [modified][solved] Pin
Mark Salsbery2-Oct-07 5:12
Mark Salsbery2-Oct-07 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.