Article View: borland.public.cppbuilder.internet.web
Article #1319Re: Active Server Object AND response->write???
From: Remy Lebeau (TeamB)
Date: Wed, 23 Mar 2005 20:24
Date: Wed, 23 Mar 2005 20:24
70 lines
2901 bytes
2901 bytes
"melk" <NOSPAMi_melk@libero.it> wrote in message
news:4241c844@newsgroups.borland.com...
> I just created a Method to write a text into my ASP using
"response->write"
> of my IResponse interface but it doesn't work... ?!?!
That is because you are not using it properly.
> m_scriptContext = (IScriptingContext*)AScriptingContext;
> m_scriptContext->get_Response((IResponse**)&rs);
Why are you retreiving the IResponse interface manually? TASPObject already
does that for you, and exposes it via its Response property. You don't need
your own OnStartPage() implementation at all.
> tagVARIANT rr;
> rr.bstrVal = (WideString)"Prova";
>
> rs->Write(rr);
That code will not work for several reasons. You did not initialize the
VARIANT before filling it in. You did not set the VARIANT's vt member to
VT_BSTR to tell the VARIANT that it contains a BSTR. You are assigning a
temporary WideString that goes out of scope immediately thus leaving the
VARIANT pointing to invalid string memory. You did not clean up the VARIANT
after using it.
Use something more like the following code instead:
STDMETHODIMP TWEBImpl::Method1()
{
try
{
VARIANT rr;
VariantInit(&rr);
rr.bstrVal = WideString("Prova").Detach();
rr.vt = VT_BSTR;
TASPObject::Response->Write(rr);
VariantClear(&rr);
}
catch(const Exception &e)
{
return Error(e.Message.c_str(), IID_IWEBImpl, E_UNEXPECTED);
}
return S_OK;
}
Which can then be simplied to the following:
#include <utilcls.h>
STDMETHODIMP TWEBImpl::Method1()
{
try
{
TVariant rr = WideString("Prova");
TASPObject::Response->Write(rr);
}
catch(const Exception &e)
{
return Error(e.Message.c_str(), IID_IWEBImpl, E_UNEXPECTED);
}
return S_OK;
}
Gambit
Technical Details
Message-ID:
<4241d051@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4241c844@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,455498a15636892c X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <4241c844@newsgroups.borland.com> Subject: Re: Active Server Object AND response->write??? Date: Wed, 23 Mar 2005 12:24:52 -0800 Lines: 72 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4241d051@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1111609425 68.69.17.41 (23 Mar 2005 12:23:45 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail