?
Solved

Http binary file transfer with MFC

Posted on 1998-10-28
4
Medium Priority
?
336 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 300 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

762 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