Discussion:
Can't print DWORD using WriteFile
(too old to reply)
Limor
2010-03-29 08:50:15 UTC
Permalink
HI all

I am tring to print 3 DWORD to a binary log and all I get is garbage

this is me code :

DWORD dwCount=0;


DWORD Tick=GetTickCount();

int anser = WriteFile(buffer->address,&ProcessId,sizeof(DWORD),&NumberIRwrit1,
NULL);

anser = WriteFile(buffer->address,&Tick,sizeof(DWORD),&NumberIRwrit2,NULL);

anser = WriteFile(buffer->address,&dwCount,sizeof(DWORD),&NumberIRwrit3,NULL)
;DWORD ProcessId=GetCurrentProcessId();



can you ples help me? this is so important and I am losing my mayend!!!!!

Thanks

Limor
Ulrich Eckhardt
2010-03-29 10:31:02 UTC
Permalink
Post by Limor
I am tring to print 3 DWORD to a binary log and all I get is garbage
What exactly is 'garbage'?
Post by Limor
int anser =
WriteFile(buffer->address,&ProcessId,sizeof(DWORD),&NumberIRwrit1, NULL);
Why is 'anser' an 'int' and not a 'BOOL', as the API says? What is the value
of 'anser'? Unless TRUE, what is the value of GetLastError()?

What is 'buffer->address'? This is supposed to be a handle to a file or
other stream, not some buffer's address, as the code suggests.

What is 'ProcessId'? It should be a 'DWORD' or of equal size. Consider
using 'sizeof ProcessId' instead.
Post by Limor
anser =
WriteFile(buffer->address,&Tick,sizeof(DWORD),&NumberIRwrit2,NULL);
Why are you overwriting 'anser' without ever checking it? Honestly, with
that kind of sloppiness, you actually deserve the garbage you get!
Post by Limor
anser =
WriteFile(buffer->address,&dwCount,sizeof(DWORD),&NumberIRwrit3,NULL)
;DWORD ProcessId=GetCurrentProcessId();
Ah, so here is 'ProcessId'! From that I can already see that the code you
compile is not the code that you posted here, so any assumptions about that
are just wild guesses.

Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
Loading...