Solved

Http binary file transfer with MFC

Posted on 1998-10-28
4
311 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
How to print into std::string like sprintf using C++11? 12 123
Create a path if not exists 7 108
No module found pypyodbc, 3 45
Outlook 13 84
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.

726 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