Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > InternetOpenUrl


Автор: Kirgston 1.2.2010, 17:08
Всем доброго времени суток! Вот собственно есть ф-ция которая должна качать файлы из инета. Но почему то всегда идет ошибка 12006.

Код

bool TUpdate::Download(AnsiString url,AnsiString dest,int i)
{
  /*    DWORD dwReserved = BINDF_GETNEWESTVERSION;

   unsigned long res = URLDownloadToFile(NULL,url.c_str(),dest.c_str(),dwReserved,NULL);
   if (res==S_OK)
   {  //Закачка выполнена
      return true;
   }
   else
    return false; */

    Form2->ProgressBar2->Position=0;
    Form2->ProgressBar2->Max=StrToInt(Form2->ListBox4->Items->Strings[i]);
    //Form2->ProgressBar2->Visible=true;
    //Form2->Label3->Visible=true;
    char buf[256];
    int errcount=0;
    UnicodeString str,agent=0;
    str=dest;

    int np;
    bool err;
    err=false;

    HINTERNET session,file;          //PRE_CONFIG_INTERNET_ACCESS INTERNET_OPEN_TYPE_PRECONFIG
    session = InternetOpen(agent.t_str(), PRE_CONFIG_INTERNET_ACCESS, 0, 0, 0);

    file    = InternetOpenUrl(session,url.c_str(), 0, 0, INTERNET_FLAG_NEED_FILE, 0);

    DWORD    Code = 0,
    Size = sizeof( Code );
    if (file==NULL)
    {
        int ErrorNum=GetLastError();
        UnicodeString ErrorMsg=L"InternetOpenUrl Error: "+IntToStr(ErrorNum);
        Application->MessageBoxA(ErrorMsg.w_str(),L"Auto Updater",MB_OK);
    }
    else
    if (HttpQueryInfo( file, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, ( LPVOID ) &Code, ( LPDWORD  ) &Size, NULL  ) )
        if (Code!=200)
            err=true;
        else
        {
            unsigned long len=0,offs=0;
            AnsiString buff="";

            if (file!=NULL)
            {
                DWORD Written;
                vector<UnicodeString>Dir;
                UnicodeString tmp;
                char* num=strtok(dest.c_str(),"\\");
                while (num!=NULL && num[strlen(num)-4]!='.')
                {
                    Dir.push_back(num);
                    num=strtok(NULL,"\\");
                }
                for (vector<UnicodeString>::size_type i=0; i < Dir.size(); i++) {
                    tmp+=Dir[i];
                    tmp+="\\";
                    CreateDirectory(tmp.t_str(),NULL);
                }
                Dir.clear();
                //char* num=strtok(dest.c_str(),"\\");
                //memcpy(tmp.t_str(),dest.c_str(),num );
               //    Dir.push_back(tmp);
                HANDLE hDestFile = CreateFile(str.t_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

                if (hDestFile == INVALID_HANDLE_VALUE)
                    err=true;
                else

                do
                {
                    Application->ProcessMessages();
                    InternetReadFile(file, buf, sizeof(buf), &len);
                    if (len>=0)
                    {
                        offs += len;
                        buff=buf;
                        WriteFile(hDestFile, buf, len, &Written, NULL);
                        Form2->ProgressBar2->Position+=len;
                        Application->ProcessMessages();
                    }

                    else
                    {
                        errcount++;
                        if (errcount>5) {
                            return false;
                        }
                        int error = GetLastError();
                        err=true;
                        InternetCloseHandle(file);
                        InternetCloseHandle(session);
                        Application->ProcessMessages();
                        ::Sleep(1000);
                        Application->ProcessMessages();
                        session = InternetOpen("Our Agent", PRE_CONFIG_INTERNET_ACCESS, 0, 0, 0);
                        file = InternetOpenUrl(session, url.c_str(), 0, 0, 0, 0);
                        InternetSetFilePointer(file, offs, 0, FILE_BEGIN, 0);
                    }

                } while (len);

                CloseHandle(hDestFile);

             }

            InternetCloseHandle(file);
            InternetCloseHandle(session);



        }

   //    Form2->ProgressBar2->Visible=false;
   //    Form2->Label3->Visible=false;

    if (!err)
        return true;
    else
        return false;
}


из МСДН видно что "The URL scheme could not be recognized, or is not supported." . А почему так?

Автор: xvr 2.2.2010, 14:30
Цитата

из МСДН видно что "The URL scheme could not be recognized, or is not supported." . А почему так? 
Видимо URL неверный  smile Чему он равен?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)