Format
#include <io.h> long _get_osfhandle(int h);
Language Level: Extension
_get_osfhandle returns the API handle corresponding to the C
run-time handle defined by h.
Return Value
If the argument is valid, _get_osfhandle returns the
corresponding API handle. If the argument is invalid,
_get_osfhandle returns -1.
Example
This example calls fileno to obtain the C run-time
standard output handle, and then maps it to an API handle. The
mapped handle is used in the WriteFile system API.
#define WIN32LEAN_AND_MEAN #include <windows.h> #include <io.h> #include <stdio.h> #include <string.h>
char s[] = "Hello";
int main(void) {
HANDLE h;
DWORD dummy;
h = (HANDLE)_get_osfhandle(fileno(stdout)); WriteFile(h, s, strlen(s), &dummy, NULL); return 0; }
![]()
_open_osfhandle
open -- Open File
_sopen -- Open Shared File
creat -- Create New File
fileno -- Determine File Handle
<fcntl.h>
#include