Click here to Skip to main content
15,927,699 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: fetching data from sql server using c++ ?? Pin
CPallini24-Dec-08 22:53
mveCPallini24-Dec-08 22:53 
AnswerRe: fetching data from sql server using c++ ?? Pin
Mark Salsbery25-Dec-08 7:00
Mark Salsbery25-Dec-08 7:00 
QuestionProblem about sending messages to the program runs on another desktop? [modified] Pin
kcynic24-Dec-08 19:13
kcynic24-Dec-08 19:13 
AnswerRe: Problem about sending messages to the program runs on another desktop? Pin
Richard Andrew x6425-Dec-08 8:13
professionalRichard Andrew x6425-Dec-08 8:13 
GeneralRe: Problem about sending messages to the program runs on another desktop? Pin
kcynic25-Dec-08 14:07
kcynic25-Dec-08 14:07 
GeneralRe: Problem about sending messages to the program runs on another desktop? Pin
Richard Andrew x6425-Dec-08 14:52
professionalRichard Andrew x6425-Dec-08 14:52 
GeneralRe: Problem about sending messages to the program runs on another desktop? Pin
kcynic25-Dec-08 14:58
kcynic25-Dec-08 14:58 
QuestionXMLHttpRequestPtr creation failed in thread? Pin
ritz123424-Dec-08 19:11
ritz123424-Dec-08 19:11 
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;
		CString strsession,szResult1,szResult;

		_bstr_t bsResponse = httpReq->responseText;

		CString response((LPCWSTR)bsResponse);
		MessageBox(response);

		nPos1=response.Find("<SessionId>");
		nPos2=response.Find("</SessionId>"); 
		nPos1+=11;
		strsession=response.Mid(nPos1,(nPos2-nPos1)); 
		m_qpWebSessionId=strsession;
		//MessageBox(m_qpWebSessionId); 

		nPos1=response.Find("<LoginToqpWebResult>");
		nPos2=response.Find("</LoginToqpWebResult>"); 
		nPos1+=20;
		
		szResult1=response.Mid(nPos1,(nPos2-nPos1)); 
		
		/*nPos1=szResult1.Find("<LoginToqpWebResult>"); 
		nPos2=szResult1.GetLength();
		nPos1+=20;
		
		szResult=szResult1.Mid(nPos1,(nPos2-nPos1)); */
		szResult=szResult1;
		szResult.MakeLower(); 
		//MessageBox(szResult);

		if(szResult=="true")
		{
			bFlg=true;
		}
		else
			MessageBox("Invalid account information.Please check your login details",_T("qpToolbar"),MB_ICONEXCLAMATION);
	}
	catch(...)
	{
		MessageBox("Login webservice not recheable");
	}
	return bFlg;
}


ritz1234

AnswerRe: XMLHttpRequestPtr creation failed in thread? Pin
Code-o-mat25-Dec-08 11:37
Code-o-mat25-Dec-08 11:37 
QuestionCheck if HWND is @ top of Z order Pin
Ravi Bhavnani24-Dec-08 18:41
professionalRavi Bhavnani24-Dec-08 18:41 
AnswerRe: Check if HWND is @ top of Z order Pin
SandipG 24-Dec-08 20:00
SandipG 24-Dec-08 20:00 
GeneralRe: Check if HWND is @ top of Z order Pin
Ravi Bhavnani25-Dec-08 5:54
professionalRavi Bhavnani25-Dec-08 5:54 
GeneralRe: Check if HWND is @ top of Z order Pin
SandipG 25-Dec-08 19:36
SandipG 25-Dec-08 19:36 
GeneralRe: Check if HWND is @ top of Z order Pin
Ravi Bhavnani26-Dec-08 9:55
professionalRavi Bhavnani26-Dec-08 9:55 
AnswerRe: Check if HWND is @ top of Z order Pin
Mark Salsbery25-Dec-08 7:07
Mark Salsbery25-Dec-08 7:07 
GeneralRe: Check if HWND is @ top of Z order Pin
Ravi Bhavnani25-Dec-08 7:13
professionalRavi Bhavnani25-Dec-08 7:13 
AnswerRe: Check if HWND is @ top of Z order Pin
Code-o-mat25-Dec-08 10:07
Code-o-mat25-Dec-08 10:07 
GeneralRe: Check if HWND is @ top of Z order Pin
Ravi Bhavnani25-Dec-08 10:56
professionalRavi Bhavnani25-Dec-08 10:56 
GeneralRe: Check if HWND is @ top of Z order Pin
Code-o-mat25-Dec-08 11:31
Code-o-mat25-Dec-08 11:31 
GeneralRe: Check if HWND is @ top of Z order Pin
Ravi Bhavnani25-Dec-08 12:29
professionalRavi Bhavnani25-Dec-08 12:29 
GeneralRe: Check if HWND is @ top of Z order Pin
Code-o-mat25-Dec-08 22:25
Code-o-mat25-Dec-08 22:25 
GeneralRe: Check if HWND is @ top of Z order Pin
Ravi Bhavnani26-Dec-08 9:56
professionalRavi Bhavnani26-Dec-08 9:56 
GeneralRe: Check if HWND is @ top of Z order Pin
Stuart Dootson25-Dec-08 22:45
professionalStuart Dootson25-Dec-08 22:45 
AnswerRe: Check if HWND is @ top of Z order Pin
Malli_S25-Dec-08 20:13
Malli_S25-Dec-08 20:13 
QuestionLong Running Program Pin
BobInNJ24-Dec-08 16:25
BobInNJ24-Dec-08 16:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.