how use IStream::CopyTo()?

i'm doing a new class ImageIStream for use the IStream more easy. but i'm getting problems :(
1
2
3
4
5
6
7
8
9
10
11
12
IStream *pIStream = nullptr;
ImageIStream(IStream *Istream)
    {
        CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pIStream);
        STATSTG cb;
        Istream->Stat(&cb,STATFLAG_DEFAULT);
        ULARGE_INTEGER *pcbRead;
        ULARGE_INTEGER *pcbWritten;
        pIStream->SetSize(cb.cbSize);
        if(Istream->CopyTo(pIStream,cb.cbSize,pcbRead,pcbWritten)!=0)
            DebugText("error on copy IStream");
    }

what i'm doing wrong for copy what is on Istream to pIStream?
Last edited on
fiinally the code is done:
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;
    }
};

how use it:
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
fb.Paint=[](HDC windowdc)//fb is my form object
    {
        //img.draw(windowdc);
        Gdiplus::GdiplusStartupInput gdiplusStartupInput;
        ULONG_PTR m_gdiplusToken;
        Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
        Gdiplus::Image imgtest3(towstring("C:\\Nova pasta\\007.gif").c_str());
        ImageIStream imgstream;
        CLSID pngClsid;
        GetEncoder("C:\\Nova pasta\\007.gif", &pngClsid);
        // Setup encoder parameters
        EncoderParameters encoderParameters;
        GetEncoderParameter(&encoderParameters);
        imgtest3.Save(imgstream, &pngClsid, &encoderParameters);

        Gdiplus::Graphics graphics(windowdc);
        graphics.DrawImage(&imgtest3, 0,0,imgtest3.GetWidth() ,imgtest3.GetHeight());
        char *christream=new char[imgstream.size()];
        christream=imgstream; //i belive these call the operator char*
        ImageIStream imgstream2(christream, imgstream.size());
        Gdiplus::Image imgtest4(imgstream2);
        BitmapDC mdc(imgtest4.GetWidth() ,imgtest4.GetHeight());
        Gdiplus::Graphics graphics2(mdc);
        graphics2.DrawImage(&imgtest3, 0,0,imgtest3.GetWidth() ,imgtest3.GetHeight());
        TransparentBlt(windowdc,0,60,imgtest4.GetWidth() ,imgtest4.GetHeight(), mdc,0,0,imgtest4.GetWidth() ,imgtest4.GetHeight(),GetPixel(mdc,0,0));
        Gdiplus::GdiplusShutdown(m_gdiplusToken);
        delete[] christream;

    };

now we can save the char* on file ;)
i hope these class helps the others.
Topic archived. No new replies allowed.