Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we convert a FILE* to a HANDLE?

Tags:

c

file

winapi

Is there any where to convert a open FILE* returned from fopen to a HANDLE that is used in the Windows API functions? If so, how?

like image 562
小太郎 Avatar asked May 19 '11 20:05

小太郎


1 Answers

(HANDLE)_get_osfhandle(_fileno( file ) )

Good luck on 64-bit systems if you're using Visual C++ 2008 or earlier, though, because the return type is long on those. :(

like image 89
user541686 Avatar answered Sep 20 '22 06:09

user541686