Using ASP objects in the components written by VC + +

Source: Internet
Author: User
Brief introduction
This article uses a simple sample to demonstrate how to invoke our familiar ASP objects (Request,response,session, and so on) in a component written in VC + + ATL. You will find that using ATL Object Wizard in Visual C + + can achieve our goal. But using Onstartpage,onendpage events is not the best approach.
In IIS3.0, components can access ASP-built objects through the Iscriptingcontext interface, but this is accessed by page-level methods. Now there is a better way to do this is to use the ObjectContext object for direct access. ObjectContext makes IIS applications more scalable and provides better transaction processing capabilities. It is highly recommended that you convert the original application to this way, but require that your application support transaction processing.
Code
First you need to include some of the necessary library files. We need mtx.h to define constants, get the IObjectContext interface through Mtxas.dll, and get the ASP object through Asp.dll.
#include <mtx.h>
#import "C:winntsystem32mtsmtxas.dll"
#import "C:winntsystem32inetsrvasp.dll"
We then transfer the IObjectContext interface.
Mtxas::objectcontextptr Pobjectcontext;
HRESULT hr = GetObjectContext ((iobjectcontext**)
&pobjectcontext);
Next, get what we need through the context object. Here are two examples: session and response.
Session Object
CComVariant v;
CComBSTR BSTR (L "session");
Ccomqiptr<igetcontextproperties, &__uuidof
(igetcontextproperties) > Pprops (pobjectcontext);
hr = Pprops->getproperty (BSTR, &AMP;V);
Ccomptr<idispatch> pdisp;
Pdisp = V_dispatch (&AMP;V);
Ccomqiptr<asptypelibrary::isessionobject, &__uuidof
(Asptypelibrary::isessionobject) > Psession (pdisp);
Response Object
CComVariant v;
CComBSTR BSTR (L "Response");
Ccomqiptr<igetcontextproperties, &__uuidof
(igetcontextproperties) > Pprops (pobjectcontext);
hr = Pprops->getproperty (BSTR, &AMP;V);
Ccomptr<idispatch> pdisp;
Pdisp = V_dispatch (&AMP;V);
Ccomqiptr<asptypelibrary::iresponse, &__uuidof
(asptypelibrary::iresponse) > Presponse (pdisp);
Finally, a simple example of using this object.
Retrieve a value from the session Object.
CComBSTR bstrvarname (L "Testsessionvar");
variant* pvalue;
Psession->get_value (Bstrvarname, pvalue);
Write that value out to the browser.
Presponse->write (pvalue);
Summarize
Although this is just a very simple in VC + + written components to invoke ASP Built-in object example, you can follow this principle to do more things. Good luck.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.