专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Javascript教程 » vc组件:在VC++ 编写的组件中使用ASP对象 »正文

vc组件:在VC++ 编写的组件中使用ASP对象

来源: 发布时间:星期四, 2009年2月12日 浏览:202次 评论:0


介绍
本文用个简单sample演示如何在VC ATL编写组件中我们熟悉ASP对象(Request,Response,Session等等)你会发现在 Visual C中使用 ATL Object Wizard就可以达到我们但使用OnStartPage,OnEndPage事件并不是最佳思路方法
在IIS3.0中组件能通过IscriptingContext 接口存取ASP内建对象但这是通过页面级思路方法来存取内建对象现在有了种更好实现思路方法就是利用ObjectContext对象直接存取ObjectContext使IIS应用有更好扩展性提供更完善事务处理功能强烈建议你把原有应用转换到这种方式但要求你应用支持事务处理
代码
首先需要包含些必要库文件我们需要mtx.h来定义些常量通过mtxas.dll得到IobjectContext接口通过asp.dll得到ASP对象
# <mtx.h>
#import \"c:Winntsystem32mtsmtxas.dll\"
#import \"c:Winntsystem32inetsrvasp.dll\"

然后我们调入IobjectContext接口
MTxAS::ObjectContextPtr pObjectContext;
HRESULT hr = GetObjectContext((IObjectContext**)
   &pObjectContext);  

通过context 对象得到我们需要东西这里举两个例子:session和response
//Session Object
CComVariant v;
CComBSTR bstr(L\"Session\");
CComQIPtr<IGetContextProperties, &__uuidof
   (IGetContextProperties)> pProps(pObjectContext);
hr = pProps->GetProperty(bstr, &v);
CComPtr<IDispatch> pDisp;
pDisp = V_DISPATCH(&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, &v);
CComPtr<IDispatch> pDisp;
pDisp = V_DISPATCH(&v);
CComQIPtr<ASPTypeLibrary::IResponse, &__uuidof
   (ASPTypeLibrary::IResponse)> pResponse(pDisp);  

最后来个使用这个对象得简单例子
//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);  

整理总结
虽然这只是个很简单在VC编写组件中ASP 内建对象例子你可以按这个原理做更多事情Good luck
       
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: