Here is the code i have been using, but it appears to leave behind a
resource leak.... (i had first done this without using _dup but that left
behind a memory leak)
What i want to be able to do is utilize an open CFile handle in code that
needs a FILE* without having to open a new file or close the existing file.
Is this possible? or should i just reopen the file by name with fopen() ?
(the CFile that would be previosly opened would ShareDenyNone)
open a CFile file
.
.
.
// Open C Runtime file handle from CFile object and open the stream
iFile = _open_osfhandle(pFile->m_hFile, _O_RDONLY);
iFile = _dup(iFile); // duplicate the file handle so when we call _fdopen
we can close it later
infile = _fdopen(iFile, "rb"); // get a valid stdio stream for the file,
now we must close with fclose
.
.
.
use the file
.
.
.
fclose(infile); // was _dup'd
-------------------
emails appreciated, but i will check back as well
e...@sunstorm.net
I think the reason the code you have leaks memory because you do not close the
the first crt handle you are returned via _open_osfhandle. I know of no way
either how you can close it except via _close which would close the os handle
for the the CFile too bummer...