1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
class ImageIStream
{
private:
char *chrpIStream = NULL;
IStream *pIStream = nullptr;
public:
ImageIStream()//working
{
CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pIStream);
}
ImageIStream(IStream *Istream)
{
CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pIStream);
ULARGE_INTEGER cb;
ULARGE_INTEGER pcbRead;
ULARGE_INTEGER pcbWritten;
LARGE_INTEGER zero;
cb.QuadPart = 0;
HRESULT hr = Istream->Seek(zero, STREAM_SEEK_SET, NULL);
Istream->CopyTo(pIStream, cb, &pcbRead, &pcbWritten);
}
ImageIStream(char *chr, int length)
{
CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pIStream);
ULONG written;
pIStream->Write(chr, length, &written);
}
void FromChar(char *chr, int length)
{
pIStream->Release();
CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pIStream);
ULONG written;
pIStream->Write(chr, length, &written);
}
void FromIStream(IStream *Istream)
{
pIStream->Release();
CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pIStream);
}
operator char*()
{
STATSTG sts;
pIStream->Stat(&sts, STATFLAG_DEFAULT);
ULARGE_INTEGER uli = sts.cbSize;
LARGE_INTEGER zero;
zero.QuadPart = 0;
ULONG size = (ULONG)uli.QuadPart;
delete[] chrpIStream;
chrpIStream= new char[size];
ULONG written;
pIStream->Seek(zero, STREAM_SEEK_SET, NULL);
pIStream->Read(chrpIStream, size, &written);
return chrpIStream;
}
int size()
{
STATSTG sts;
pIStream->Stat(&sts, STATFLAG_DEFAULT);
ULARGE_INTEGER uli = sts.cbSize;
LARGE_INTEGER zero;
zero.QuadPart = 0;
ULONG intsize = (ULONG)uli.QuadPart;
return (int)intsize;
}
operator IStream*()//wroking
{
return pIStream;
}
~ImageIStream()
{
pIStream->Release();
delete[] chrpIStream;
}
};
|