0

I'm to convert an std::ifstream into a FILE* handle in Windows. I googled a lot about this problem and people say that it is possible to get the underlying file descriptor of the fstream with the function fstream::fd(). The problem is that in Visual Studio there's no way to make it work (it says that the class has no member fd). In which library can I find this function? I included the usual C++ fstream.

#include <fstream>    

FILE* handle;
std::ifstream file;
file.open(file_to_open);
if (file.is_open()) {
    std::ifstream f;
    handle = f.fd();
    file.close();
}

EDIT: If there's another function in Windows that allows to open a file without calling internally CreateFileA function, it would be appreciated.

  • https://stackoverflow.com/questions/109449/getting-a-file-from-a-stdfstream – Geza Lore Oct 12 '18 at 19:41
  • I need this conversion for IAT hooking on fopen function: I already hooked all CreateFileA functions to open a certain file in my executable and the problem is that fopen calls internally CreateFileA to do it's job. What happens is that the fopen function doesn't open anymore the file it was used to open, but opens the one I specified in the hooked version of CreateFileA. what I need is a differnt way to open a file but to return a FILE* type. – Mark Ferrer Oct 13 '18 at 10:14

0 Answers0