CString GetStringFromUrl(LPCTSTR pszUrl)
{
CString str ;
HINTERNET hSession = ::InternetOpen( _T("4399GameBox") , INTERNET_OPEN_TYPE_PRECONFIG ,
NULL , NULL , 0 ) ;
if( hSession )
{
HINTERNET hHttpFile = ::InternetOpenUrl( hSession , pszUrl , NULL , 0 , 0 , 0 ) ;
if( hHttpFile )
{
// 获得文件的大小
TCHAR szSizeBuffer [ MAX_PATH ] ;
DWORD dwLengthSizeBuffer = sizeof(szSizeBuffer);
if( ::HttpQueryInfo( hHttpFile , HTTP_QUERY_CONTENT_LENGTH , szSizeBuffer ,
&dwLengthSizeBuffer , NULL ) )
{
DWORD dwFileSize = _ttol( szSizeBuffer ) ;
DWORD dwBytesRead = 0 ;
CMemBlock mem( dwFileSize + 1 , TRUE ) ;
if( ::InternetReadFile( hHttpFile , mem.GetData() , dwFileSize , &dwBytesRead ) )
{
str = (LPCSTR)mem.GetData() ;
}
}
::InternetCloseHandle( hHttpFile ) ;
}
::InternetCloseHandle( hSession ) ;
}
return str ;
}