Link to home
Start Free TrialLog in
Avatar of nikola_mk
nikola_mk

asked on

Wininet downloading file .When I start with downloading my project is blocked (freezed).

I use Wininet lib. for downloading file from internet. When I start with downloading my project is blocked (freezed).
How can i fix this problem?

I use this method for downloading file:

{
var
hInternetO,hHInternetC,hResource:HINTERNET;
FileStream:TFileStream;
DataProceed:array[0..1023] of Char;
NumRead,i:Cardinal;
kraj:Boolean;
begin

  hInternetO:=InternetOpen( 'Naslov',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0 );
  hHInternetC:=InternetConnect( HInternetO,PAnsiChar(Host),INTERNET_DEFAULT_HTTP_PORT,nil,nil,INTERNET_SERVICE_HTTP,0,0);
  hResource := HttpOpenRequest(hHInternetC, 'GET', PChar(Resource), nil, nil, nil, 0, 0);
  HttpSendRequest(hResource, nil, 0, nil, 0);

  ///
   try
     FileStream := TFileStream.Create('c:\', FileOpenModes[FileExists('c:\')]);
    except
     ShowMessage('Please enter valid URL !');
     Exit;
    end;
  try
    FileStream.Position := Result;
    repeat
      ZeroMemory(@DataProceed, SizeOf(DataProceed));

      InternetReadFile(hResource, @DataProceed, SizeOf(DataProceed)-1, NumRead);

      if (NumRead <= 0) then Break;
      FileStream.Write(DataProceed, NumRead);
      Result := Result + Integer(NumRead);

    until Kraj=true;
  finally
    FileStream.Free();
    InternetCloseHandle(hHInternetC);
    InternetCloseHandle(hInternetO);
  end;
}

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of gmayo
gmayo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial