newbie needs help, basic mfc stuff

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 2
Reputation: brouhaha is an unknown quantity at this point 
Solved Threads: 0
brouhaha brouhaha is offline Offline
Newbie Poster

newbie needs help, basic mfc stuff

 
0
  #1
Jan 3rd, 2005
hello. Sorry for the long post. My ultimate goal is to make a program that can read text off a website, if told the url, when to start reading, and where to stop, and then write the text to a textfile. This is all easy once I am able to read the source code of the html doc given its url. Sooooo... I found this code from Planet Source Code, it claims to be able to read source code of a given url. A couple people responded to it, one person said they couldnt get it to work, another person said it worked great, so I think it probably works. But I am in the camp that cannot get it to work. I make a normal win32 app and in properties i select Use Shared MFC dll. This makes the CString opperations work but the other ones such as CInternetSession do not work, they give me errors of CInternetSession undeclared identifier. I remembered to put in #include <afxinet.h> so i dont understand what is wrong. Can someone please help a newbie??? Here is the code:


//**************************************
//
#include <afxinet.h>
//**************************************
//
// Name: ^!!~ A better HTML Source Grabb
// er/Stealer ~!!^
// Descriptionimple example of how to
// grab(some people like ti call it 'steal'
// ) the HTML source of a page from a appli
// cation... There are a couple of examples
// here at PSC, but they are not very good
// because they use ReadHuge to store all o
// f the data in a buffer which can cause m
// emory problems, incomplete page sources,
// and of course ugly boxes due to no carri
// age returns or line breaks... This ReadS
// tring version is alot more efficent... I
// t works 100% in MFC... And since this co
// de is so easy to implement into virtuall
// y any project, I am NOT going to post th
// e project files unless I get alot of req
// uests
// By: Zak Farrington
//
// Assumes:Make sure to define m_strURL
// and m_strSource via ClassWizard
//
//This code is copyrighted and has// limited warranties.Please see http://
// www.Planet-Source-Code.com/vb/scripts/Sh
// owCode.asp?txtCodeId=7754&lngWId=3//for details.//**************************************
//

//** Make sure you add two edit boxes to
// your dialog, make the one for the URL in
// put a CString named 'm_strURL'
//** And to store the source add another
// edit box(Make sure its multi line), make
// it a CString named 'm_strSource'

void CYourDialogClass::OnYourEvent()
{
UpdateData(TRUE); //** Perform DDX and get user input
CInternetSession session; //** define our internet session
CInternetFile* pFile = (CInternetFile *)session.OpenURL(m_strURL); //** define our internet file that will hold the source
if(pFile) //** If we can OpenURL(m_strURL)


{
CString string; //** Create a buffer string
while (pFile->ReadString(string) != NULL) //** Read as many string as we can until we run into EOF(End Of File)


{
m_strSource += string; //** Add the string of data we just read
m_strSource += "\r\n"; //** Add a line break to make it look better
}
}
UpdateData(FALSE);
}
edit to add: I am using microsoft visual c++ .net
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 2
Reputation: brouhaha is an unknown quantity at this point 
Solved Threads: 0
brouhaha brouhaha is offline Offline
Newbie Poster

Re: newbie needs help, basic mfc stuff

 
0
  #2
Jan 3rd, 2005
I fixed it by making a new project, still a win32 app, and made it a console project (which is what I normally do) and selected Add MFC support, (which I had done before) and then also clicked Add ATL support.

Can someone explain why adding ATL support made the afxinet class work?

I also had to delete the UpdateData lines. Those didnt make sense anyway.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC