Board index » cppbuilder » File handle to TFileStream?
Nataraj
![]() CBuilder Developer |
Nataraj
![]() CBuilder Developer |
File handle to TFileStream?2007-07-26 10:20:07 PM cppbuilder101 I have a file handle created using Win32 API CreateFile(). Is it possible to construct a TFileStream object from this handle? Because I need to provide backward compatibility in my application. |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2007-07-27 02:31:35 AM
Re:File handle to TFileStream?
"Nataraj" < XXXX@XXXXX.COM >wrote in message
QuoteI have a file handle created QuoteBecause I need to provide backward (TFileStream derives from THandleStream). THandleStream's constructor takes a file handle as input, ie: HANDLE hFile = CreateFile(...); THandleStream *pStream = new THandleStream((int)hFile); ... delete pStream; CloseHandle(hFile); If you must use a TFileStream, then you are probably out of luck. Normally, I would suggest deriving your own class from TFileStream so that you can access THandleStream's FHandle member directly. But your descendant class can't bypass TFileStream's constructor, which requires TFileStream to open the file. You *might* be able to construct a THandleStream directly and then typecast it to a TFileStream, since TFileStream does not introduce any new data members. But I'm not sure if that would work. Gambit |
Nataraj
![]() CBuilder Developer |
2007-07-31 05:01:03 PM
Re:File handle to TFileStream?
Success. I could create a THandleStream from
hFile and do TFileStream operations on it. No issues. Worked fine. Thanks a lot for the suggestion! -Nataraj Quote
{smallsort} |