In terms of Windows is not strong, so I apologize in advance for the possible inaccuracy of the names.
Description of the problem:
There is a network card device file that is located at. \ Global {some-windows-hash} .tap
The file opens like this
std::wstring userModeDevice = L"\\\\.\\Global\\"; userModeDevice += WinRegReader::getDeviceGuid() + L".tap"; _fileHandle = CreateFile ( userModeDevice.c_str(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM|FILE_FLAG_OVERLAPPED, nullptr); Further, through DeviceIoControl () with the file the necessary manipulations are performed. It's all ok, and it works.
But I really want to get a file handle from _fileHandle, which is of type HANDLE - int (for such functions to work like read / write).
There are many examples of how this can be done, of which approximately this follows.
int fd = _open_osfhandle((intptr_t)_fileHandle, O_RDWR); for example, here , but they all refer to user-space files, but if "\\. \ Global \" is used, the function returns -1, and errno is a constant corresponding to the text "Invalid argument".
Tell me how you can get an int handle from HANDLE (\\. \ Global \ ...), if at all possible. Thank.