Solved

Http binary file transfer with MFC

Posted on 1998-10-28
4
283 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now