🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #1328

Re: Active Server Object PART 2

#1328
From: melk
Date: Fri, 25 Mar 2005 16:15
77 lines
3515 bytes
Hi Thanks for your replay, I tried to use but it seems doesn't work!!! I
know that it coused by me, but I realy net Help...

this is the code you sent me with my integration...; the first time I tried
to use it, it gave me a memory write error so I only add a line to malloc
"data" before memcpy...
Now it doesn't give me any error, but no picture was write to the page...
I tried olso to get the header text from the IIS response, and it doesn't
contain the bitmap byte...

I olso tried to write to file the "data" buffer whitout pass from the
"SafeArrayAccessData(v.parray, &data)" function and it write the picture
file well!!!

        Graphics::TBitmap *bmp = new Graphics::TBitmap();
        TJPEGImage *jpg = new TJPEGImage();

        TRect re(0,0,50,50);
        bmp->Width = 100;
        bmp->Height = 100;
        bmp->Canvas->Brush->Color = clBlue;
        bmp->Canvas->FillRect(re);

        jpg->Assign(bmp);
        jpg->CompressionQuality = 30;

        Response->put_Buffer(true);
        Response->put_Expires(0);
        Response->Clear();

        try
        {
            std::auto_ptr<TMemoryStream> MemStream(new TMemoryStream);
            jpg->SaveToStream(MemStream.get());

            SAFEARRAYBOUND bounds = {0, MemStream->Size-1};

            TVariant v;
            v.parray = ::SafeArrayCreate(VT_UI1, 1, &bounds);
            v.vt = VT_ARRAY|VT_UI1;

            if( v.parray == NULL )
                throw Exception("Cannot create the array of bytes");

            void *data = NULL;

            //Get a pointer to beginning of data area in Jpeginmemory
            if( FAILED(::SafeArrayAccessData(v.parray, &data)) )
                throw Exception("Cannot access the array of bytes");

            //Copy jpeg data to it
            data = malloc(sizeof(byte)*MemStream->Size);
            memcpy(data, MemStream->Memory, MemStream->Size);

            //Unlock the data
            ::SafeArrayUnaccessData(v.parray);

            Response->put_Status(WideString("200 OK"));
            Response->put_ContentType(WideString("image/jpeg"));
            Response->AddHeader(WideString("Content-Length"),
                                   WideString(IntToStr(MemStream->Size)));

            Response->BinaryWrite(v);
            Response->End();

            free(data);
        }
        catch(const Exception &e)
        {
            Response->Clear();
            Response->put_Status(WideString("500 " + e.Message));
        }

        Response->Flush();

        delete jpg;
        delete bmp;
Technical Details
Message-ID: <42443927@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4242c7fd@newsgroups.borland.com> <42431956$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,1b87c7406bae033
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "melk" <NOSPAMi_melk@libero.it>
Newsgroups: borland.public.cppbuilder.internet.web
References: <4242c7fd@newsgroups.borland.com> <42431956$1@newsgroups.borland.com>
Subject: Re: Active Server Object PART 2
Date: Fri, 25 Mar 2005 17:15:30 +0100
Lines: 83
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1478
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1478
NNTP-Posting-Host: 81.208.118.242
Message-ID: <42443927@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1111767335 81.208.118.242 (25 Mar 2005 08:15:35 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail