Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

IStream interface file reading



  • HI, i've recently fall in this problem: I have an IStream interface that read a file as a stream. For read the stream i can use IStream::Read. The problem is that it need a as a parameter the number of bytes to read. the problem is that i'dont now how many bytes pass to the function since each time the file size change, other that i don't know how how many bytes to allocate for the buffer to store the file content.

    @
    STATSTG pstatstg;
    m_pStream->Stat(&pstatstg, STATFLAG_DEFAULT);

    const int size(pstatstg.cbSize.LowPart);

    ULONG pcbRead;
    BYTE pBuffer[10000] ; //How many bytes to allocate??

    m_pStream->Read(pBuffer,9999, &pcbRead); //How many bytes to read? this should be equal to pBuffer size...

    @

    I've tried to use pstatstg.cbSize.LowPart that return the size of the file, but it give me an error cause size isn't costant and i can't use it to initialize the array(pBuffer)

    Thanks in advance!



  • BYTE* pBuffer = malloc(number_of_bytes);

    Don't forget to "free(pBuffer);" when you are done using it.



  • Really thanks for the reply! It worked but i have other problem now: i can't read completly a file of 3 Mb of size. Instead for other file less of 1 Mb, i can read it, but the importer dont reconize the contente. Instead if allocate "manually" a fixed number of bytes i.e 3084 the importer can read it also if the file is not complete...


Log in to reply