944,192 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4396
  • C++ RSS
Jan 3rd, 2005
0

newbie needs help, basic mfc stuff

Expand Post »
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:


Quote ...
//**************************************
//
#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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
brouhaha is offline Offline
2 posts
since Jan 2005
Jan 3rd, 2005
0

Re: newbie needs help, basic mfc stuff

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
brouhaha is offline Offline
2 posts
since Jan 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Visual c++ libraries
Next Thread in C++ Forum Timeline: Basic help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC