Re: IXMLHTTPRequest AJAX trace
Igor,
Sorry for keep asking questions. ICustomXMLHTTPRequest is the interface
exposed that was created by VC automatically when I created a new ATL
class. So I have implemented two class objects of what you suggested.
One is called CWrapper which implements IXMLHTTPRequest only and
nothing else and the other one is called CCaller which only implements
IClassFactory. I think I got the COM_MAP correct this time. Regardless
of the correctness of the CreateInstance implementation in Caller.cpp,
CreateInstance still never gets call anyway when I put breakpoints
around it. I am so frustrated that I don't understand why. Below is the
code. Would you please help me with the section of code(possibly give
me a working example) where CreateInstance will be called by other
application using IXMLHTTPRequest interface once your own class factory
is registered and associated with CLSID_XMLHTTP properly? From there I
can probably figure out the rest. I spent all day and couldn't even get
started. Thank you very much.
Best Regards,
Paulino
+++++++++Code to Register+++++++++++
CoInitialize(NULL);
IClassFactory* original;
DWORD dwRegister = NULL;
//save the original XMLHTTP class factory
HRESULT hr =
CoGetClassObject(CLSID_XMLHTTP,CLSCTX_ALL,NULL,IID_IClassFactory,(void**)&original);
IClassFactory* pCaller = NULL;
hr =
CoCreateInstance(CLSID_Caller,NULL,CLSCTX_ALL,IID_IClassFactory,(void**)&pCaller);
//assoicate our caller with XMLHTTPRequest's CLSID
hr =
CoRegisterClassObject(CLSID_XMLHTTP,(IUnknown*)pCaller,CLSCTX_INPROC_SERVER,REGCLS_MULTIPLEUSE,&dwRegister);
++++++++++++++++++++++++++++++++
++++++++++Wrapper.h++++++++++++++
class CWrapper :
public CComObjectRoot,
public CComCoClass<CWrapper,&CLSID_Wrapper>,
public IXMLHTTPRequest
{
public:
CWrapper() {m_pXMLHTTPRequest.CoCreateInstance(CLSID_XMLHTTP);}
BEGIN_COM_MAP(CWrapper)
COM_INTERFACE_ENTRY(IXMLHTTPRequest)
END_COM_MAP()
//DECLARE_NOT_AGGREGATABLE(CWrapper)
// Remove the comment from the line above if you don't want your object
to
// support aggregation.
DECLARE_REGISTRY_RESOURCEID(IDR_Wrapper)
public:
//IXMLHTTPRequest members
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);
//IDispatch members
STDMETHOD (GetTypeInfoCount)(UINT *pctinfo);
STDMETHOD (GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo);
STDMETHOD (GetIDsOfNames)(REFIID riid, LPOLESTR *rgszNames, UINT
cNames, LCID lcid, DISPID *rgDispId);
STDMETHOD (Invoke)(DISPID dispIdMember,REFIID riid,LCID lcid, WORD
wFlags, DISPPARAMS *pDispParams,VARIANT *pVarResult, EXCEPINFO
*pExcepInfo, UINT *puArgErr);
private:
CComPtr<IXMLHTTPRequest> m_pXMLHTTPRequest;
};
+++++++++++++++++++++++++++++++
++++++++++Caller.h+++++++++++++++
class CCaller :
public CComObjectRoot,
public CComCoClass<CCaller,&CLSID_Caller>,
public IClassFactory
{
public:
CCaller() {}
BEGIN_COM_MAP(CCaller)
COM_INTERFACE_ENTRY(IClassFactory)
END_COM_MAP()
//DECLARE_NOT_AGGREGATABLE(CCaller)
// Remove the comment from the line above if you don't want your object
to
// support aggregation.
DECLARE_REGISTRY_RESOURCEID(IDR_Caller)
public:
//IClassFactory members
STDMETHOD (CreateInstance)(IUnknown *, REFIID iid, void **ppv);
STDMETHOD (LockServer)(BOOL);
};
+++++++++++++++++++++++++++++++
+++++++++++Caller.cpp+++++++++++++
STDMETHODIMP CCaller::CreateInstance(IUnknown *pUnkOuter, REFIID riid,
void **ppvObject)
{
HRESULT hr =
CoCreateInstance(CLSID_Wrapper,NULL,CLSCTX_INPROC_SERVER,IID_IXMLHTTPRequest,(void**)&ppvObject);
return hr;
}
STDMETHODIMP CCaller::LockServer(BOOL fLock)
{
return NOERROR;
}
++++++++++++++++++++++++++++++++