Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    IStream interface file reading

    C++ Gurus
    2
    3
    2313
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      ceora last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • S
        ScottR last edited by

        BYTE* pBuffer = malloc(number_of_bytes);

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

        1 Reply Last reply Reply Quote 0
        • C
          ceora last edited by

          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...

          1 Reply Last reply Reply Quote 0
          • First post
            Last post