然后,我们调入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。