Reputation: 1069
I have a problem with ReadFile function in a virtual serial port:
char tmp[128];
int multiplo=0;
DWORD err;
COMSTAT stt;
ClearCommError(hcom, &err, &stt);
do{
if(ReadFile(hcom, tmp, stt.cbInQue, &err, NULL)){
tmp[err] = '\0';
memcpy(bfIn+multiplo, tmp, err);
multiplo = multiplo + err;
}else
return 0;
}while(err > 0);
this code works when ReadFile get valid character like 0x01, 0x02, 0x03... but there is a problem with 0x00, the code doesn't read like I expected, I try with hyperterminal and that works perfect.
I've defined in dcb structure:
dcb.fNull = false;
but still I have the same problem, any help?
Upvotes: 1
Views: 1128
Reputation: 14964
The problem seems to be not in ReadFile() but rather in your use of tmp[] as the terminating '\0' happens to be 0x00, too.
What do you mean by "doesn't read like I expected"? Can you describe the symptoms in more detail?
Upvotes: 0