Einzelnen Beitrag anzeigen

drama22

Registriert seit: 12. Jan 2013
88 Beiträge
 
#1

winnet download thread

  Alt 22. Mai 2015, 22:53
iam using this code to download some images from web to memory stream inside activex its freezing too much when large image size i asked on the web they told me to put this code inside a thread i fail to do it any help with it ? here is the code

Delphi-Quellcode:
procedure DownloadToStream(const Url: string; ms: TMemoryStream);
var
  hSession : HINTERNET;
  hService : HINTERNET;
  lpBuffer : array[0..1023] of Byte;
  dwBytesRead : DWORD;
  dwBytesAvail : DWORD;
  dwTimeOut : DWORD;
begin
  hSession := InternetOpen('sessionname', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if not Assigned(hSession) then Exit;
  try
    hService := InternetOpenUrl(hSession, PChar(Url), nil, 0, 0, 0);
    if hService = nil then
      Exit;
    try
      dwTimeOut := 60000;
      InternetSetOption(hService, INTERNET_OPTION_RECEIVE_TIMEOUT, @dwTimeOut, SizeOf(dwTimeOut));
      if InternetQueryDataAvailable(hService, dwBytesAvail, 0, 0) then
      repeat
      Application.ProcessMessages;
        if not InternetReadFile(hService, @lpBuffer[0], SizeOf(lpBuffer), dwBytesRead) then
          Break;
        if dwBytesRead <> 0 then
          ms.WriteBuffer(lpBuffer[0], dwBytesRead);
      until dwBytesRead = 0;
    finally
      InternetCloseHandle(hService);
    end;
  finally
    InternetCloseHandle(hSession);
  end;
end;
  Mit Zitat antworten Zitat