Thread View: borland.public.cppbuilder.internet.web
6 messages
6 total messages
Started by melk
Thu, 24 Mar 2005 14:00
Active Server Object PART 2
Author: melk
Date: Thu, 24 Mar 2005 14:00
Date: Thu, 24 Mar 2005 14:00
14 lines
1362 bytes
1362 bytes
Hi, I'm just here with another question... I have to write out to the ASP page directly a JPEG byte array, first I tried to looking for a Method of IRepsonse Interface "ContentStream" that I saw use in Delphi code but i can't find it in BC++ 6... this method accept a Stream type like one that exit from TJPEGImage::SaveToStream.. finaly I tried to use IResponse::binaryWrite without effect, it doesn't write on the page.. olso using some direct character string, like IResponse::write using method, but it seems dosen't work?!?! THNKS!!!
Re: Active Server Object PART 2
Author: Remy Lebeau (TeamB)
Date: Thu, 24 Mar 2005 19:48
Date: Thu, 24 Mar 2005 19:48
80 lines
3407 bytes
3407 bytes
"melk" <NOSPAMi_melk@libero.it> wrote in message
news:4242c7fd@newsgroups.borland.com...
> I have to write out to the ASP page directly a JPEG byte array,
There are several steps you have to do in order for that to work.
1) prepare a VARIANT that contains a SAFEARRAY that contains the raw bytes
2) set the IResponse::ContentType property to "image/jpeg".
3) call IResponse::AddHeader() to add an additional "Content-Length" header
value.
4) pass the VARIANT to IResponse::BinaryWrite().
> first I tried to looking for a Method of IRepsonse Interface
"ContentStream"
> that I saw use in Delphi code but i can't find it in BC++ 6...
There is no such property/method in IResponse. The Delphi code must have
been using something else.
> this method accept a Stream type like one that exit from
TJPEGImage::SaveToStream..
You are probably looking at code realted to the Indy library
(http://www.indyproject.org). That has nothing to do with ASP programming.
> finaly I tried to use IResponse::binaryWrite without effect, it
> doesn't write on the page..
BinaryWrite() is what you need to use. You probably just did not set it up
properly. Try the following code:
#include <memory>
{
Response->Clear();
Response->put_Buffer(VARIANT_TRUE);
try
{
std::auto_ptr<TMemoryStream> MemStream(new TMemoryStream);
JPEGImage->SaveToStream(MemStream.get());
SAFEARRRAYBOUND 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;
if( FAILED(::SafeArrayAccessData(v.parray, &data)) )
throw Exception("Cannot access the array of bytes");
memcpy(data, MemStream->Memory, MemStream->Size);
::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);
}
catch(const Exception &e)
{
Response->Clear();
Response->put_Status(WideString("500 " + e.Message));
}
Response->Flush();
}
Gambit
Re: Active Server Object PART 2
Author: melk
Date: Fri, 25 Mar 2005 16:15
Date: Fri, 25 Mar 2005 16:15
77 lines
3515 bytes
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;
Re: Active Server Object PART 2
Author: Remy Lebeau (TeamB)
Date: Fri, 25 Mar 2005 18:32
Date: Fri, 25 Mar 2005 18:32
49 lines
2330 bytes
2330 bytes
"melk" <NOSPAMi_melk@libero.it> wrote in message
news:42443927@newsgroups.borland.com...
> Hi Thanks for your replay, I tried to use but it seems doesn't work!!!
Just saying it doesn't work says nothing about the actual problem you are
having.
> 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...
That was not the correct thing to do.
> 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!!!
You allocated memory for the buffer yourself instead of letting
SafeArrayAccessData() do it for you.
> Graphics::TBitmap *bmp = new Graphics::TBitmap();
> TJPEGImage *jpg = new TJPEGImage();
Wrap those in try...catch or try..finally blocks, or use an std::auto_ptr,
to ensure the memory is freed correctly in case an exception occurs.
> SAFEARRAYBOUND bounds = {0, MemStream->Size-1};
Change that to this instead:
SAFEARRAYBOUND bounds;
bounds.lLbound = 0;
bounds.cElements = MemStream->Size;
> data = malloc(sizeof(byte)*MemStream->Size);
Get rid of that.
> Response->End();
You don't need to call that since Flush() is called later.
> free(data);
Get rid of that.
Gambit
Re: Active Server Object PART 2
Author: melk
Date: Wed, 30 Mar 2005 12:13
Date: Wed, 30 Mar 2005 12:13
61 lines
2711 bytes
2711 bytes
Thank you it works right!!
I'm finding a lots of difficulty to try without debuging... do you now if
there is some method to debug this kind of object?
Thanks again!!
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> ha scritto nel messaggio
news:424458ef$1@newsgroups.borland.com...
>
> "melk" <NOSPAMi_melk@libero.it> wrote in message
> news:42443927@newsgroups.borland.com...
>
> > Hi Thanks for your replay, I tried to use but it seems doesn't work!!!
>
> Just saying it doesn't work says nothing about the actual problem you are
> having.
>
> > 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...
>
> That was not the correct thing to do.
>
> > 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!!!
>
> You allocated memory for the buffer yourself instead of letting
> SafeArrayAccessData() do it for you.
>
> > Graphics::TBitmap *bmp = new Graphics::TBitmap();
> > TJPEGImage *jpg = new TJPEGImage();
>
> Wrap those in try...catch or try..finally blocks, or use an std::auto_ptr,
> to ensure the memory is freed correctly in case an exception occurs.
>
> > SAFEARRAYBOUND bounds = {0, MemStream->Size-1};
>
> Change that to this instead:
>
> SAFEARRAYBOUND bounds;
> bounds.lLbound = 0;
> bounds.cElements = MemStream->Size;
>
> > data = malloc(sizeof(byte)*MemStream->Size);
>
> Get rid of that.
>
> > Response->End();
>
> You don't need to call that since Flush() is called later.
>
> > free(data);
>
> Get rid of that.
>
>
> Gambit
>
>
Re: Active Server Object PART 2
Author: Remy Lebeau (TeamB)
Date: Wed, 30 Mar 2005 18:18
Date: Wed, 30 Mar 2005 18:18
19 lines
1700 bytes
1700 bytes
"melk" <NOSPAMi_melk@libero.it> wrote in message
news:424a9805@newsgroups.borland.com...
> I'm finding a lots of difficulty to try without debuging... do you now if
> there is some method to debug this kind of object?
Yes, there is a way, but not with Borland's tools, at least not entirely.
Have a look at the following article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;196378
You can probably attach the BCB debugger to the appropriate process, but
getting it to debug just the specific ASP object after that may be tricky.
To be honest, I have never tried to debug the internals of an ASP object
before, so I cannot provide you with any futher help in that area.
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads