Solved

Http binary file transfer with MFC

Posted on 1998-10-28
4
322 Views
Last Modified: 2012-05-04
I need to know how to make a download of http binary files with wininet...i try lots of API functions and I can't put it to work. Please it is veru URGENT...
0
Comment
Question by:osda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1176440
Try going here:

http://www.codeguru.com/internet/index.shtml

There are a lot of articles dealing with MFC and the internet.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1176441
If you "urgently" need an answer, this is the wrong place. You should call Microsoft's Product Support Services and get interactive support over the phone.

B ekiM


0
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
ID: 1176442
In the meantime, here's the core of a console app that will grab the experts exchange logo from this very website and copy it to C:\MyCopy.GIF on your hard drive.  Obviously, the GIF file is binary.

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
      int nRetCode = 0;

      // initialize MFC and print and error on failure
      if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
      {
            // TODO: change error code to suit your needs
            cerr << _T("Fatal Error: MFC initialization failed") << endl;
            nRetCode = 1;
      }
      else
      {
            CInternetSession sess;

            CHttpConnection* pConnection = NULL;
            CHttpFile* pFile = NULL;

            try
            {
                  pConnection = sess.GetHttpConnection("www.experts-exchange.com");

                  pFile = pConnection->OpenRequest(
                              CHttpConnection::HTTP_VERB_GET, "/images/logoag395x50.gif");
                  pFile->SendRequest();

                  CFile fileOut("C:\\MyCopy.GIF",
                        CFile::modeCreate | CFile::typeBinary | CFile::modeWrite);

                  BYTE sz[1024];
                  UINT nRead;

                  do
                  {
                        nRead = pFile->Read(sz, 1024);
                        fileOut.Write(sz, nRead);
                  }
                  while (nRead > 0);

                  fileOut.Close();
            }
            catch (CInternetException* pEx)
            {
                  char sz[1024];
                  pEx->GetErrorMessage(sz, 1024);
                  cerr << "Internet Error!  ";
                  cerr << sz;
                  cerr << endl;
            }
            catch (CFileException* pEx)
            {
                  char sz[1024];
                  pEx->GetErrorMessage(sz, 1024);
                  cerr << "File Error!  ";
                  cerr << sz;
                  cerr << endl;
            }

            if (pFile != NULL)
                  pFile->Close();
            delete pFile;

            if (pConnection != NULL)
                  pConnection->Close();
            delete pConnection;

      sess.Close();
   }

   return nRetCode;
}



B ekiM
0
 

Author Comment

by:osda
ID: 1176443
Your code was very usefull for me...but it is almost the same of my code......i just forgot to put CFile::typeBinary plag in my CFlie..... :-))))  thanx anyway.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 clear a vector as well as how to detect empty vectors in C++.

691 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