🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10784

HTTP download

#10784
From: Becze Tibor
Date: Sun, 14 Mar 2004 14:39
75 lines
3193 bytes
Hali!

I have a 'small' problem. My code download the files with HTTP, but i can't
read the file size. If somebody can help, please write.

Becze Tibor

int InternetHttpDownLoad(HWND hwndProgressbar, HWND hwndSay, char *cURL,
char *cOutFile){
  int iRet;
  HINTERNET hINet, hFile;
  hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL,
NULL, 0 );
  if (hINet) {
    hFile = InternetOpenUrl(hINet, cURL, NULL, 0, 0, 0);
    if (hFile) {
      DWORD NumberOfBytesAvailable = 0;



      iRet = InternetQueryDataAvailable(hFile, &NumberOfBytesAvailable,
NULL, NULL);    //  it is my problem NumberOfBytesAvailable variable is not
valid.



      if (iRet){
        long lMax = 1000000;  // i changed NumberOfBytesAvailable -> lMax
because work.
        char *buffer = new char[lMax];
        char cTmp[MAX_PATH];
        DWORD lCurPos = 0, lPercent;
        DWORD dwRead;
        if (hwndProgressbar){
          SendMessage(hwndProgressbar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
          SendMessage(hwndProgressbar, PBM_SETPOS, 0, 0);
        }
        if (hwndSay){
          SendMessage(hwndSay, WM_SETTEXT, 0, (LONG)cURL);
        }
        iRet = InternetReadFile(hFile, &buffer[lCurPos], 1024, &dwRead);
        while (iRet && dwRead > 0 && lCurPos < lMax- 1024) {
          lCurPos += dwRead;
          if (hwndProgressbar){
            lPercent = lCurPos* 100/ NumberOfBytesAvailable;
            SendMessage(hwndProgressbar, PBM_SETPOS, lPercent, 0);
          }
          if (hwndSay){
            sprintf(cTmp, "%s - %ld", cURL, lCurPos);
            SendMessage(hwndSay, WM_SETTEXT, 0, (LONG)cTmp);
          }
          iRet = InternetReadFile(hFile, &buffer[lCurPos], 1024, &dwRead);
        }
/*
        files fOut(cOutFile);
        iRet = fOut.Open(GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_RANDOM_ACCESS);
        if (iRet){
          unsigned long WriteByte;
          iRet = fOut.Write(buffer, lCurPos, &WriteByte);
          fOut.Close();
        }
*/
        delete [] buffer;
      }
      InternetCloseHandle(hFile);
    } else {
      iRet = false;
    }
    InternetCloseHandle(hINet);
  } else {
    iRet = false;
  }
  return iRet;
}
Technical Details
Message-ID: <40546ecb@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,87694c47dea140c,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-03-14 06:42:12 PST
Reply-To: "Becze Tibor" <becze@freemail.hu>
From: "Becze Tibor" <becze@freemail.hu>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: HTTP download
Date: Sun, 14 Mar 2004 15:39:42 +0100
Lines: 77
Organization: RIWO Kft.
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 195.38.114.9
Message-ID: <40546ecb@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1079275211 195.38.114.9 (14 Mar 2004 06:40:11 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail