HANDLE and FILE*

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello everyone,


I am using Windows API open (create) a new file by CreateFile,

http://msdn2.microsoft.com/en-us/library/aa363858.aspx

the return value is HANDLE, if I use fwrite to write content to the file,
since fwrite requires FILE* as parameter. I think HANDLE is not the same as
FILE*, right?

Are there any ways (or methods) to transform HANDLE to FILE*?

I have tried that passing HANDLE directly to fwrite (forcely convert from
HANDLE from FILE*) will cause access violation exception. I think the reason
is HANDLE is not the same as FILE*, is that correct?


thanks in advance,
George
 
I am using Windows API open (create) a new file by CreateFile,
the return value is HANDLE, if I use fwrite to write content to the file,
since fwrite requires FILE* as parameter. I think HANDLE is not the same as
FILE*, right?
Correct.

Are there any ways (or methods) to transform HANDLE to FILE*?

Possibly (with a fair bit of hassle), but why don't you just take the
easy route and use the correct set of APIs? If you want a FILE *, open
the file with fopen.

Dave
 
Thanks for your advice, David.

David Lowndes said:
Possibly (with a fair bit of hassle), but why don't you just take the
easy route and use the correct set of APIs? If you want a FILE *, open
the file with fopen.

Dave


regards,
George
 
George said:
Are there any ways (or methods) to transform HANDLE to FILE*?

Dave is correct, you shouldn't mix metaphors. But if you must, take a look
at the docs for this function

_open_osfhandle()

Regards,
Will
 
Back
Top