Re: IXMLHTTPRequest AJAX trace
Igor,
I worked with Jason and I have implemented what you have suggested, but
nothing happened when I execute the code. Here is the code:
////////////////////////////////////////////////////////////////////////
CoInitialize(NULL);
CComPtr<IClassFactory> original;
DWORD dwRegister = NULL;
//save the original IXMLHTTPRequest
hr =
CoGetClassObject(CLSID_XMLHTTP,CLSCTX_ALL,NULL,IID_IClassFactory,(void**)&original);
//our wrapper
CComPtr<ICustomXMLHTTPRequest> icxmlhttp;
//create an instance of icxmlhttp
hr = icxmlhttp.CoCreateInstance(CLSID_CustomXMLHTTPRequest);
//assoicate our wrapper with XMLHTTPRequest's CLSID
hr =
CoRegisterClassObject(CLSID_XMLHTTP,icxmlhttp,CLSCTX_LOCAL_SERVER,REGCLS_MULTIPLEUSE,&dwRegister);
//////////////////////////////////////////////////////////////////////
CCustomXMLHTTPRequest is the wrapper class to preview XMLHTTPRequest's
call and it implements all the interface of IXMLHTTPRequest. Below is
the code of the wrapper class
//////////////////////////////////////////////////////////////
class CCustomXMLHTTPRequest :
public IDispatchImpl<ICustomXMLHTTPRequest,
&IID_ICustomXMLHTTPRequest, &LIBID_IEEnumWindowsLib>,
public CComObjectRoot,
public CComCoClass<CCustomXMLHTTPRequest,&CLSID_CustomXMLHTTPRequest>,
public IXMLHTTPRequest
{
public:
CCustomXMLHTTPRequest()
{m_pXMLHTTPRequest.CoCreateInstance(CLSID_XMLHTTP);}
BEGIN_COM_MAP(CCustomXMLHTTPRequest)
//COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY2(IDispatch, ICustomXMLHTTPRequest)
COM_INTERFACE_ENTRY(ICustomXMLHTTPRequest)
END_COM_MAP()
public:
STDMETHOD (setRequestHeader)(BSTR bstrHeader,BSTR bstrValue);
STDMETHOD (open)(BSTR bstrMethod, BSTR bstrUrl, VARIANT varAsync,
VARIANT bstrUser, VARIANT bstrPassword);
STDMETHOD (getResponseHeader)(BSTR bstrHeader, BSTR *pbstrValue);
STDMETHOD (getAllResponseHeaders)(BSTR *pbstrHeaders);
STDMETHOD (send)(VARIANT varBody);
STDMETHOD (abort)(void);
STDMETHOD (get_status)(long *plStatus);
STDMETHOD (get_statusText)(BSTR *pbstrStatus);
STDMETHOD (get_responseXML)(IDispatch **ppBody);
STDMETHOD (get_responseText)(BSTR *pbstrBody);
STDMETHOD (get_responseBody)(VARIANT *pvarBody);
STDMETHOD (get_responseStream)(VARIANT *pvarBody);
STDMETHOD (get_readyState)(long *plState);
STDMETHOD (put_onreadystatechange)(IDispatch *pReadyStateSink);
private:
CComPtr<IXMLHTTPRequest> m_pXMLHTTPRequest;
////////////////////////////////////////////////////////////////////////////////////////
I haven't put my own code in the functions and I simply do a redirect
back to IXMLHTTPRequest, such as:
/////////////////////////////////////////////////////////////////////////////
STDMETHODIMP CCustomXMLHTTPRequest::setRequestHeader(BSTR
bstrHeader,BSTR bstrValue)
{
return m_pXMLHTTPRequest->setRequestHeader(bstrHeader,bstrValue);
}
//////////////////////////////////////////////////////////////////////////
My question is the functions did not get call after I have supposingly
associated my own class factory with XMLHTTPRequest's CLSID using
CoRegisterClassObject. Does the logic seem correct to you? Do I miss
anything making it doesn't work? Please advice. Thank you
Paulino