News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

HFILE

Started by Biterider, November 20, 2017, 04:34:17 AM

Previous topic - Next topic

Biterider

Hi
Moving some part of my old code to x64 I stumbled over the HFILE definition in WinBase.inc



_HFILE_DEFINED EQU <>
HFILE  typedef DWORD
endif



Shouldn't it be a HANDLE = 64 bit?


Regards, Biterider

Vortex

Hi Biterider,

Reading windef.h supplied with Pelles C :

typedef int HFILE;

sizeof(int)=4

Testing this Pelles C code ( 64-bit project ) :

#include <stdio.h>
#include <windows.h>

int main()
{
printf("sizeof(HFILE)=%llu",sizeof(HFILE));
return 0;
}


Output :
sizeof(HFILE)=4

jj2007

Right. I stumbled over this some time ago, it is indeed very odd:
HFILE
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(
HANDLE WINAPI CreateFile(

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:

hutch--

File handles in Win64 are 64 bit. Either,

hFile dq ?  ; .DATA section
or
LOCAL hFile :QWORD

jj2007

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"
EndOfCode


Output:This code was assembled with ml64 in 64-bit format
Handle
rax     60
$Err$()
Operazione completata.

$rsi    C:\Masm32\qEditor.exe
hit any key