Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. IStream interface file reading
Forum Updated to NodeBB v4.3 + New Features

IStream interface file reading

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 2.6k Views 1 Watching
  • 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 Offline
    C Offline
    ceora
    wrote on last edited by
    #1

    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
    0
    • S Offline
      S Offline
      ScottR
      wrote on last edited by
      #2

      BYTE* pBuffer = malloc(number_of_bytes);

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ceora
        wrote on last edited by
        #3

        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved