[Lazarus] WinINet STDCALL callback crash

Ludo Brands ludo.brands at free.fr
Sat Mar 9 10:12:13 CET 2013


On 03/04/2013 12:45 AM, matthew at accordancebible.com wrote:
> Ludo, 
> 
> Thank you very much for your most informative posting.  I have spent the week trying to implement the msdn examples in pure Pascal and in Pascal-DLL hybrids.  Success in non-threaded asynchrosity eludes me though.  
> 
> Your example (http://www.lazarus.freepascal.org/index.php?topic=18506.15#msg105226) using URLMON's URLDownloadToFile works perfectly.  However, the example is synchronous whilst we need asynchronous.  Research indicates that URLOpenPullStream is the more relevant function in our case (because we download asynchronously to both memory streams and files, depending on what flags the user sets and can track the progress of the download).  The problem is that URLOpenPullStream and URLDownloadToFile (which I am using as an intermediate coding step) both require a variable of a type that implements the IBindStatusCallback interface, which in turn requires declaration of the IBinding interface.  I have tried doing so without success; I share my code below.  
> 
> Is there a way to access the UrlMon.dll's definition of IBindStatus and IBinding so that these interfaces are available within Lazarus?  Currently, the only option I see is to define these interfaces myself.  Alternatively, is there an example of a Lazarus definition of these interfaces?
> 
> FYI, after the program segfaults, the assembler window points within urlmon!ZonesReInit
> 
> Thank you for any help you might provide.
> 
This is definitely the most difficult route to async you are trying to
walk;) Delphi has an unit to support urlmon that defines all these
interfaces but I still have to see a stable and reliable piece of code
that manages to use URLOpenPullStream. Also quite some knowledge on COM
interfaces is need to try to get that working. For example
QueryInterface := E_NOTIMPL; is a no go in interfaces.

Why don't you use a standard async library such as lNet
(http://wiki.freepascal.org/lNet, http://lnet.wordpress.com/)? It has a
lazarus package that will install amongst others the
TLHTTPClientComponent that has already the necessary events. The library
comes with a httpclienttest example application that show you how to use
the component.
There is also Indy (http://wiki.freepascal.org/Indy_with_Lazarus) which
is async although that library is much bigger and compatibility with
lazarus is not that good as well as its portability to other platforms.

Ludo





More information about the Lazarus mailing list