Hello Dear Friends, 1) I am creating an application which allows its user to log in to website. 2) For that I call the webservice(Written in C#.NET) from the MFC. 3) To call the webservices I use the XMLHttpRequest and it is working fine if I call the webservice using XMLHttpRequest with the member function of the class, However this method doesn't allow the parent program to continue until I get the webservice response. 4) So I am creating a thread and calling the webservice from the thread the problem is in the thread it won't allow to create the COM object of XMLHttpRequestPtr.Can anybody tell me what could be the reason that the creation of the COM object fails. 5) Please see the code below.
void LOGINTOWEB(void *Params)
{
CMFToolbar *m_pToolbar=(CMFToolbar*)Params;
try
{
CSingleLock m_lock(&(m_pToolbar->m_sema));
m_lock.Lock();
m_pToolbar->LoginToWeb1(m_pToolbar->m_strqpWebUser,m_pToolbar->m_strqpWebPass,m_pToolbar->m_strqpWebOrg,m_pToolbar->m_strqpWebUrl);
m_lock.Unlock();
_endthread();
}
catch(...)
{
}
}
And here is the member function of the class I've debug the code it fails in the creation of the COM object IXMLHttpRequestPrt
bool CMFToolbar::LoginToWeb1(CString UserName,CString Password,CString Organization,CString Url)
{
bool bFlg=false;
try
{
CString params;
/* Here the exception is generated when called from the thread. When this function called without any thread it will run.Why it fails in thread?????*/
MSXML::IXMLHttpRequestPtr httpReq(__uuidof(XMLHTTPRequest));
\_bstr\_t HTTPMethod ;
\_variant\_t noAsync = \_variant\_t( (bool)false );
\_variant\_t user=\_variant\_t((CString)UserName);
\_variant\_t pass=\_variant\_t((CString)Password);
CString strUrl=Url;
strUrl+=QPWEB\_SUFFIX;
//MessageBox(strUrl);
\_bstr\_t url(strUrl.GetBuffer(strUrl.GetLength()));
HTTPMethod = \_bstr\_t("GET");
httpReq->open(HTTPMethod,url,noAsync,vtMissing,vtMissing);
httpReq->setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
httpReq->setRequestHeader("Content-Length","0");
params.Empty();
params="UserName=";
params+=UserName;
params+="&Password=";
params+=Password;
params+="&Organization=";
params+=Organization;
//MessageBox(params);
VARIANT vRequest;
vRequest.vt = VT\_BSTR;
vRequest.bstrVal = params.AllocSysString();
httpReq->send(vRequest);
BSTR strText;
int nPos1,nPos2;
CSt