5

How can I implement the following Windows function in Delphi?

HRESULT URLDownloadToFile(      
  LPUNKNOWN pCaller,
  LPCTSTR szURL,
  LPCTSTR szFileName,
  DWORD dwReserved,
  LPBINDSTATUSCALLBACK lpfnCB
);  

URLDownloadToFile Function: http://msdn.microsoft.com/en-us/library/ms775123(VS.85).aspx

The question that prompted me was asked here.

Downloading flv from youtube using curlpp on top of curl - video not playing

Regards, Pieter.

Community
  • 1
  • 1
Pieter van Wyk
  • 2,316
  • 9
  • 48
  • 65

2 Answers2

11
uses
  URLMon, ShellApi;

function DownloadFile(SourceFile, DestFile: string): Boolean;
begin
  try
    Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
  except
    Result := False;
  end;
end;
G-Man
  • 7,232
  • 18
  • 72
  • 100
-1

Without header file we can not know what is LPBINDSTATUSCALLBACK for example. The best approach is to google around if someone has already made a conversion of the whole header file. If there isn't one, then try some C to Delphi convertor (http://www.drbob42.com/delphi/headconv.htm, http://cc.embarcadero.com/item/26951). Beware that they can only convert 60-80% of the code, but hopefully part you are interested in will be converted. If you are still stuck after all this, then search for VB conversion of the header. It will be much easier then conversion from C.

avra
  • 1