ECOLN - Search Cambridgeshire


Here is a portion of code from the C++ 'browser' program from which it is possible to browse to any accessible web page and thence index it and upload the index in precisely two key clicks. This is a very small amount of the code involved. I will upload more code in due course, when I get the time.
The following function is called to index the page currently visible in the browser. The indexing is done by a class written in visual basic and incapsulated in the DLL 'ECOLNIndexdMod'. The object 'pDLL' is made from this class in the following line...
_largeWordMapClassPtr pDLL("ECOLNIndexMod.LargeWordMapClass");
The index is made by calling the ECOLNIndexMod function 'makeList' as seen in the line...
(CString)(char *) pDLL->makeList(&myHTMLSource.bstrVal);
Once the index is prepared, a dialog appears giving a brief analysis of the indexed document. A button on this dialog will cause another function to upload the index information to the server.
	void CMainFrame::MakeIndex()
	{

		//assumes server, port and URL names have been initialized
		CInternetSession session("www.ecoln.com Cambridgeshire Search");
		CHttpConnection* pServer = NULL;
		CHttpFile* pFile = NULL;
		try

		{


			CString strServerName;
			m_wndDlgBar.GetDlgItem(IDC_EADDRESS)->GetWindowText(strServerName);
			//AfxMessageBox(strServerName);

			if (strServerName.GetLength() > 7)
			{
				CString tempStr = strServerName.Left(7);
				tempStr.MakeLower();
				if ( tempStr == "http://")
				{
					strServerName = strServerName.Right (strServerName.GetLength() -7);
				}

			}


		   INTERNET_PORT nPort = 80;

			CString strObject = "";	

			DWORD dwRet = 0;
			char szBuff[1023];
			CString myString;

			int slashPos = strServerName.FindOneOf ("/");
			int strLen = strServerName.GetLength();
			if (slashPos < strLen - 1) 
				strObject = strServerName.Right (strLen - slashPos - 1);
			if (slashPos > -1)
				strServerName = strServerName.Left (slashPos);


		   pServer = session.GetHttpConnection(strServerName, nPort);
		   pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject);

		   pFile->AddRequestHeaders(szHeaders);			   

		   pFile->SendRequest();
		   pFile->QueryInfoStatusCode(dwRet);		

		   if (dwRet == HTTP_STATUS_OK)
		   {
				TCHAR sz[1024];
				int nRead = 1024;

				while (nRead > 0)
				{
					nRead = pFile->Read(sz, 1023);
					sz[nRead] = '\0';
					myString = myString + (CString)sz ;
				}


				_largeWordMapClassPtr  pDLL("ECOLNIndexMod.LargeWordMapClass");

				//See article an 'VARIANT and VARIANTARG' from 'Automation: Platform SDK'	

							//myString = strServerName + "\\" + strObject;

				_variant_t myHTMLSource (myString);


				pDLL->initializeStuff();

				//ShowDialog.m_strShowText  = myString = strServerName + "/" + strObject + "\n";

				//20020718
				int eqPos = 0;
				while (eqPos >= 0){
					eqPos = strObject.Find('=',eqPos);
					int strObLen = strObject.GetLength();
					if (eqPos >= 0){ 
						CString rPart = strObject.Right (strObLen - eqPos -1);
						CString lPart = strObject.Left (eqPos);
						strObject = lPart + "%3d" + rPart;
						eqPos = eqPos + 3;
					}
				}


				myString = "ixurl=" + strServerName + "/" + strObject + "\r\n";

				ShowDialog.m_strShowText  = myString;
				ShowDialog.m_strURL = strServerName + "/" + strObject;


				ShowDialog.m_strShowText  = ShowDialog.m_strShowText +
					(CString)(char *) pDLL->makeList(&myHTMLSource.bstrVal);
				ShowDialog.m_strURL = strServerName + "/" + strObject;
				ShowDialog.m_unsHTMLSrc = &myHTMLSource.bstrVal;


				UpdateData(FALSE);
				ShowDialog.DoModal();

		   }
		   else {AfxMessageBox("Download failed at index point \r\n" + (CString)szHeaders);}


		   delete pFile;
		   delete pServer;


		}
		catch (CInternetException* pEx)
		{
		   //catch errors from WinInet
			AfxMessageBox("Download failed on WinInet exception \r\n" + (CString)szHeaders);

		}

	session.Close();

	}