News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Invalid Filehandle

Started by justnew, January 08, 2011, 04:33:26 PM

Previous topic - Next topic

justnew

Hi
I'm realy confused. First the code worked but from the one to the other second I get an invalid FIlehandle when I open a file.
That's my bugy code:

.386
.model flat, stdcall
option casemap:none

[...]

.data
[...]

.data?
hFile HANDLE ?

.code
[...]
;Read File
invoke CreateFile,addr file,GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
mov hFile,eax
.if hFile == INVALID_HANDLE_VALUE
call errorBox
.endif
invoke ReadFile,hFile,addr buffer,sizeof buffer,addr bread,addr rckeep   ;Here I get the error
.if eax == FALSE
call errorBox
.endif
invoke CloseHandle,hFile

The Filehandle is 34 and nothing overwrites it (I watched at the debugger).

If you want I can upload the exe too (its about 13kb but 10kb is used for data).

clive

ZIP it up an attach. Providing incomplete code makes it difficult to debug or review.

What the heck is rckeep doing, you surely aren't doing overlapped io, for most cases you should use NULL, because that parameter is a handle too.
It could be a random act of randomness. Those happen a lot as well.

japheth


For overlapped I/O, it might be necessary to set FILE_FLAG_OVERLAPPED in CreateFile().

justnew

Quote from: clive on January 08, 2011, 04:43:35 PM
What the heck is rckeep doing, you surely aren't doing overlapped io, for most cases you should use NULL, because that parameter is a handle too.

I luv u XD.
Yeah rckeep was the invalid handle. Thank you very much.
The next time I should read the documantation more carefully :S.