Пример #1
0
CString   CUpdateApp::GetWebStieHtml(CString  strUrl)
{
	CInternetSession mySession(NULL,0);  
	CHttpFile* myHttpFile = NULL;
	myHttpFile = (CHttpFile*)mySession.OpenURL(strUrl);//str是要打开的地址
	CString myData;
	CString  csHtmlContent;
	while(myHttpFile->ReadString(myData)) 
	{
		csHtmlContent += myData; 
	}

	return  csHtmlContent;
}
Пример #2
0
	AINIKU_API CString getUrl2(CString url) {
		if (url == "") { return ""; }
		CInternetSession mySession((LPCTSTR)"aaa", 0);//如果不指定aaa(随便的一个字符串)的话debug模式下会报错
		CHttpFile* htmlFile = NULL;
		CString str, strHtml;
		TRY{
			htmlFile = (CHttpFile*)mySession.OpenURL(url);//打开连接
		while (htmlFile->ReadString(str)) {
			char *pStr = (char*)str.GetBuffer(str.GetLength()); //取得str对象的原始字符串
			int nBufferSize = MultiByteToWideChar(CP_UTF8, 0, pStr, -1, NULL, 0); //取得所需缓存的多少
			wchar_t *pBuffer = (wchar_t*)malloc(nBufferSize * sizeof(wchar_t));//申请缓存空间
			MultiByteToWideChar(CP_UTF8, 0, pStr, -1, pBuffer, nBufferSize*sizeof(wchar_t));//转码
			strHtml += pBuffer;
			free(pBuffer); //释放缓存	
		}
		return strHtml;
		}CATCH(CException, e){
			TCHAR err[1024];
			e->GetErrorMessage(err, 1024);
			return "";
		}
Пример #3
0
int getIndexData(void)
{
	CInternetSession mySession(NULL,0);
	CHttpFile* myHttpFile = NULL;
	CString myData;
	CString myURL;
	int i = 0;
	myURL = m_URL + _T(A50ID) + _T(HS300ID);
	try{
		myHttpFile = (CHttpFile*)mySession.OpenURL(myURL);
	}
	catch(CInternetException*pException){
		pException->Delete();
		return -1;//读取失败,返回
	}
	if(myHttpFile != NULL){
		try{
			while(myHttpFile->ReadString(myData))
			{
				CString strGet1(_T("")); 
				CString strGet2(_T(""));
				CString strGet3(_T(""));
				double temp = 0;
				AfxExtractSubString(strGet1,myData,1, _T('\"'));
				AfxExtractSubString(strGet2,strGet1,3, _T(','));//现在的价格
				AfxExtractSubString(strGet3,strGet1,2, _T(','));//昨天的价格
				LPTSTR  chValue = strGet2.GetBuffer( strGet2.GetLength() );
				LPTSTR  chValueZT = strGet3.GetBuffer( strGet3.GetLength() );
				double fValue = atof(chValue); //今天的价格
				double fZT = atof(chValueZT);//昨天的价格
				strGet2.ReleaseBuffer(); 
				if(fValue > 0.1){//防止等于0,等于0就用昨天的收盘价
					price[i] = fValue;
				}
				else{
					price[i] = fZT;
				}
				i++;
			}
		}
		catch(CInternetException*pException){
			pException->Delete();
			return -1;//返回
		}

	}
	//计算A50和HS300指数
	double totalValueA50 = 0;
	double totalValueHS300 = 0;
	for(int i = 0;i < TOTAL;i++){
		if(i < A50NUM){
			totalValueA50 = totalValueA50 + price[i] * volume[i];
		}
		if(i >= A50NUM){
			totalValueHS300 = totalValueHS300 + price[i] * volume[i];
		}
	}
	::EnterCriticalSection(&g_index);
	A50Index = A50IndexRef * totalValueA50 / A50totalVolumeRef;
	HS300Index = HS300IndexRef * totalValueHS300 / HS300totalVolumeRef;
	::LeaveCriticalSection(&g_index);
	myHttpFile->Close();
	delete myHttpFile;
	mySession.Close();
	return 0;
}