I try to make a search on many web search engines.
I need your help to understand how I must do it.
I join my project
PCTSTR rgpszAcceptTypes[] = {
_T("text/*"),
_T("video/*"),
_T("image/*"),
_T("audio/*"),
NULL
} ;
char szEngineTitle[] = _T("My HTTP Search Engine") ;
char szGet[] = _T("GET") ;
char szBingSearch[] = _T("search?q=%s") ;
char szBingEngine[] = _T("http://www.bing.com") ;
LPSTR Search_OnTheWeb(LPSTR __lpszEngine,LPSTR __lpszVerb,LPDWORD __lpResultLength)
{
HINTERNET _hInternet, _hConnect, _hRequest ;
DWORD _dwContentLen, _dwBufLen, _cReadCount, _dwBytesRead, _dwReadSize ;
DWORD _dwError ;
LPSTR _lpData, _lpCopyPtr ;
_hInternet = _hConnect = _hRequest = NULL ;
_dwReadSize = _dwContentLen = _cReadCount = _dwBytesRead = _dwBufLen = _dwError = 0 ;
_lpData = _lpCopyPtr = NULL ;
*__lpResultLength = 0 ;
if(__lpszEngine)
{
if(__lpszVerb)
{
if(__lpResultLength)
{
_hInternet = InternetOpen(szEngineTitle,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0) ;
if(_hInternet)
{
_hConnect = InternetConnect(_hInternet,__lpszEngine,INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0) ;
if(_hConnect)
{
_hRequest = HttpOpenRequest(_hConnect,szGet,__lpszVerb,NULL,NULL,rgpszAcceptTypes,INTERNET_FLAG_RELOAD,0) ;
if(_hRequest)
{
if(HttpSendRequest(_hRequest,NULL,0,NULL,0))
{
_dwBufLen = sizeof(_dwContentLen) ;
if(!HttpQueryInfo(_hRequest,HTTP_QUERY_CONTENT_LENGTH|HTTP_QUERY_FLAG_NUMBER,(LPVOID)&_dwContentLen,&_dwBufLen,0))
{
_dwError = GetLastError() ;
if(_dwError == ERROR_HTTP_HEADER_NOT_FOUND)
{
InternetCloseHandle(_hRequest) ;
InternetCloseHandle(_hInternet) ;
InternetCloseHandle(_hConnect) ;
return (NULL) ;
}
else
{
if(_dwError == ERROR_INSUFFICIENT_BUFFER)
{
_lpData = (LPSTR) HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_dwContentLen + 1) ;
if(_lpData)
{
// We will read 10% of data with each read.
_dwReadSize = _dwContentLen / 10 ;
_lpCopyPtr = _lpData ;
for(_cReadCount = 0 ; _cReadCount < 10 ; _cReadCount++)
{
InternetReadFile(_hRequest,_lpCopyPtr,_dwReadSize,&_dwBytesRead) ;
_lpCopyPtr = _lpCopyPtr + _dwBytesRead ;
}
// Extra read to account for integer division round off
InternetReadFile(_hRequest,_lpCopyPtr,_dwContentLen - (_lpCopyPtr - _lpData),&_dwBytesRead) ;
// Null terminate data
_lpData[_dwContentLen] = 0 ;
*__lpResultLength = _dwContentLen ;
}
}
}
}
InternetCloseHandle(_hRequest) ;
}
InternetCloseHandle(_hInternet) ;
}
InternetCloseHandle(_hConnect) ;
}
}
}
}
}
return (_lpData) ;
}
LPSTR Search_Bing(LPSTR __lpszString,LPDWORD __lpResultLength)
{
char _szTmp[1024] ;
wsprintf(_szTmp,szBingSearch,__lpszString) ;
return (Search_OnTheWeb(szBingEngine,_szTmp,__lpResultLength)) ;
}
LPSTR Search_Google(LPSTR __lpszString,LPDWORD __lpResultLength)
{
char _szTmp[1024] ;
wsprintf(_szTmp,szGoogleSearch,__lpszString) ;
return (Search_OnTheWeb(szGoogleEngine,_szTmp,__lpResultLength)) ;
}
The problem is at the line : HttpSendRequest(_hRequest,NULL,0,NULL,0)
Could you help me please?
Thanks