This article was written by Benjamin aka chaosben. He kindly agreed to publish it here. You can also publish articles here. Mail us @ mail(-at+)delphi-jedi.net
Getting started with BITS
BITS, the Background Intelligent Transfer Service, provides an easy way to
download/upload files from/to the network/internet. You may have heard of this
service in the context of the automatic Windows Update and you are right -
Microsoft uses it to get the files on the computer.
Ok, I know, you want to start coding. Thats why our first step is to add the
units ActiveX, ComObj and JwaBits to the uses clause of our project.
In the next step, we have ensure, that the COM library is initialized for the
current thread. It sounds hard, but it is easy (thanks to Sebastian):
Just write this part at the end of your unit before the final “end.”
Fine, now we have a nice environment for messing around with BITS. Let’s
grab an interface to a BackgoundCopyMananger. After declaring a variable
(I call it “FManager”) of type IBackgroundCopyManager, it can be
initialized as follow:
Don’t forget to free the interface at the end of the program. Just write:
As our first test with BITS, we want to see, which jobs are currently running.
I dropped a listbox and a timer on a form and filled the OnTimer-Event with this code:
Ok, that’s it. Play around with the interface to get in touch with them.
Maybe another article will follow.
Benjamin aka chaosben
www.TheUnknownOnes.net
—
You can get to the second part of BITS here.
Download
The new BITS header conversion units will be available through the JEDI API Release. They actually are not available. Thus we provide them as download here.
Notice:
The code examples above do not use these new units, however. Thus you can just include JwaBits.pas (or JwaWindows).
7 Responses
Ajasja
26|Apr|2008 1There’s a small error:
an end of line is missing on line 14
//maybe the right is missing … try to get just our jobs if not Succeeded(Res) then
should be
//maybe the right is missing … try to get just our jobs
if not Succeeded(Res) then
Otherwise keep up the good work.
Maybe for part two: how to actually download something and how to host the downloads?:)
Best regards,
Ajasja
Christian Wimmer
26|Apr|2008 2Thank you. The code is fixed. I also added:
“Notice:
The code examples above do not use these new units, however. Thus you can just include JwaBits.pas (or JwaWindows).”
I hope the author does write a new article
Chaosben
26|Apr|2008 3Thanks for the reply Ajasja.
I’m thinking about the continuation and you are right: starting own downloads is much more interesting.
Sebastian
26|Apr|2008 4CoUnitialize should only be called when CoInitializeEx succeeded. Otherwise the call to CoUnitialize will shut down com too early. Use CoInitFlags in the initialization section, and Delphi will take care of it.
initialization
CoInitFlags := COINIT_APARTMENTTHREADED;
end.
Chaosben
27|Apr|2008 5Thank you Sebastian for this improvement. It was new to me.
For all others: Include “ComObj” into your uses clause in order to get this feature working. Doing it the way, Sebastian mentioned, above you can omit the two lines “CoInitializeEx” and “CoUninitialize”.
I’ll try to correct the listings.
Stéphane Wierzbicki
27|Apr|2008 6Thank you for sharing the article. I also hope the author does write a new article with :
- how to actually download something (lan shares / ftp / http)
- how to host the downloads (lan shares / ftp / http)
Bits Part 2 - Downloading files by JEDI Windows API
30|Apr|2008 7[...] hope you enjoyed the first part of the introduction to BITS. In this second part, we want to improve our job list (a little bit) [...]
Leave a reply
Search
Paypal donation (EUR)
Categories
Most Viewed
Archives
Tags
ACL callback COM Conversion CreateProcess DACL Delphi dialog DidYouKnow DLL documentation Download elevation factory file Handle header HowTo interface JWA JWSCL Kernel Microsoft KillProcess Laptop mail mailinglist manifest permission Privilege Process ProcessExplorer RunEl Russinovich Service Setup Sid TerminateProcess Theme Thread Token UAC user Vista Window WindowsRecent Posts
Recent Comments
Blogroll
Pages
Meta
A design creation of Design Disease
Copyright © 2007 - JEDI Windows API - is proudly powered by WordPress
InSense 1.0 Theme by Design Disease brought to you by HostGator Web Hosting.