windows 如何获取IStream的长度?C++

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1561370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:16:52  来源:igfitidea点击:

How to get the length of IStream? C++

c++windowsstream

提问by Schwertz

I'm creating an IStream as follow:

我正在创建一个 IStream 如下:

IStream* stream;
result = CreateStreamOnHGlobal(0, TRUE, &stream);

Then I have a CImage object that I save to this stream:

然后我有一个保存到这个流的 CImage 对象:

image->Save(stream, Gdiplus::ImageFormatBMP);

I need to get the size of bytes written to this IStream.

我需要获取写入此 IStream 的字节大小。

How can I do this?

我怎样才能做到这一点?

There is no Length or something like this in the IStream...

IStream 中没有 Length 或类似的东西......

thanks!

谢谢!

回答by Christopher

IStream::Statshould do what you want.

IStream::Stat应该做你想做的。

回答by Harald Deischinger

Or you can use:

或者你可以使用:

    ULARGE_INTEGER liSize;
    IStream_Size(pStream, &liSize);

other functions you might find useful in this context:

在这种情况下,您可能会发现其他有用的功能:

    IStream_Reset(pStream);         // reset seek position to beginning
    IStream_Read(pStream, mem, size);