Right. I stumbled over this some time ago, it is indeed very odd:
HFILE (https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx)
QuoteA handle to a file opened by OpenFile, not CreateFile.
This type is declared in WinDef.h as follows:
typedef int HFILE;
Note the "OpenFile, not CreateFile". It seems a legacy thing...
HFILE WINAPI OpenFile( (https://msdn.microsoft.com/en-us/library/windows/desktop/aa365430%28v=vs.85%29.aspx)
HANDLE WINAPI CreateFile( (https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx)
The VS header files obscure it, as usual, maybe these are the original definitions:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\WTypes.h
typedef INT HFILE;
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\WinNT.h
typedef PVOID HANDLE;
But there is also this definition in WinDef.h:
#ifndef _MAC
typedef int HFILE;
typedef HICON HCURSOR; /* HICONs & HCURSORs are polymorphic */
#else
typedef short HFILE;
DECLARE_HANDLE(HCURSOR); /* HICONs & HCURSORs are not polymorphic */
#endif
So if you are on a Mac, it's a short :biggrin:
File handles in Win64 are 64 bit. Either,
hFile dq ? ; .DATA section
or
LOCAL hFile :QWORD
Quote from: hutch-- on November 20, 2017, 08:02:47 AM
File handles in Win64 are 64 bit. Either,
hFile dq ? ; .DATA section
or
LOCAL hFile :QWORD
With the exception of the handle returned by OpenFile. Test it yourself...
include \Masm32\MasmBasic\Res\JBasic.inc
.data?
ofs OFSTRUCT <>
Init ; OPT_64 1 ; put 0 for 32 bit, 1 for 64 bit assembly
PrintLine Chr$("This code was assembled with ", @AsmUsed$(1), " in ", jbit$, "-bit format")
; int 3
usedeb=1
jinvoke OpenFile, Chr$("\Masm32\qEditor.exe"), addr ofs, OF_READ
; towards the end of OpenFile:
; 00000000779E0953 | 8B C7 | mov eax, edi
mov rsi, offset ofs.szPathName
deb 4, "Handle", rax, $Err$(), $rsi
jinvoke CloseHandle, rax
Inkey "hit any key"
EndOfCodeOutput:
This code was assembled with ml64 in 64-bit format
Handle
rax 60
$Err$()
Operazione completata.
$rsi C:\Masm32\qEditor.exe
hit any key