Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Http binary file transfer with MFC

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

636 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