Solved

File handler

Posted on 2000-03-24
3
270 Views
Last Modified: 2010-04-02
Hullo,

When using the OpenUrl function in MFC it returns a file handler as follows

Returns a file handle for FTP, GOPHER, HTTP, and FILE-type Internet services only. Returns NULL if parsing was unsuccessful.

The pointer that OpenURL returns depends on pszURL’s type of service. The table below illustrates the possible pointers OpenURL can return.

URL type Returns
file:// CStdioFile*
http:// CHttpFile*
gopher:// CGopherFile*
ftp:// CInternetFile*

When I have this I want to read the file into an array.
Any ideas on how i might do this?
the handler in this case will be CHttpFile as it is a file I am reading from a http site.

thanks
0
Comment
Question by:sambo12
3 Comments
 
LVL 9

Expert Comment

by:Pacman
ID: 2653602
Can't you just read the bytes via member function "Read()" ?
0
 

Expert Comment

by:maxd128
ID: 2655635
Simply asign returned pointer to CFile* and use it's member functions.
0
 

Accepted Solution

by:
vidz7 earned 25 total points
ID: 2772906
hi sambo..... hope this helps u:

CInternetSession is;
      CHttpConnection *hc;
      CHttpFile *hf;
      DWORD dwRead;
      BYTE buffer[6000];      
      CFile lf("try.zip",CFile::modeCreate | CFile::modeWrite );
      
      try
      {
            hf=(CHttpFile*)is.OpenURL("GIVE UR URL HERE...eg: http://microsoft.com/dirmap.txt",1,INTERNET_FLAG_TRANSFER_BINARY);
                        
         dwRead = hf->Read(buffer,hf->GetLength());
             lf.Write(buffer, dwRead);
            
        AfxMessageBox("Done");


      }
      catch(CInternetException ex){AfxMessageBox("BOMBED");}
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question