Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between HANDLE and HFILE in WinAPI?

Tags:

file

winapi

WinAPI OpenFile function returns HFILE, and GetFileTime for instance needs HANDLE. When I feed it with (HANDLE)some_hFile it seems to work fine. Is there any difference in this types, or one of these is simply rudimental?

like image 937
akalenuk Avatar asked Nov 26 '08 14:11

akalenuk


3 Answers

OpenFile is a 16-bit Windows backward-compatibility function. CreateFile is the function to open files.

like image 193
Barry Kelly Avatar answered Dec 01 '22 17:12

Barry Kelly


If the function succeeds then HFILE is a file HANDLE. If not, then it is an HFILE_ERROR constant (presumably -1). The point is that it can't be a HANDLE on error so they return something that can be either a HANDLE or an error value.

See @Barry's suggestion as well.

like image 45
tvanfosson Avatar answered Dec 01 '22 15:12

tvanfosson


To answer your question, HANDLE is just an unsigned 32bit number defined as PVOID. It is a generic handle. HFILE is a specialized handle, although defined as signed 32bit number to be able to get value -1.
There are other specialized handles, like HACCEL, HBITMAP, HINSTANCE, etc., all defined as a dependence to HANDLE.

like image 22
PhiLho Avatar answered Dec 01 '22 16:12

PhiLho