|Delphi Clinic||C++Builder Gate||Training & Consultancy||Delphi Notes Weblog||Dr.Bob's Webshop|
Win32 Interaction for the Faint-Hearted
Delphi is a great tool for Windows application development. However, there are situations where Delphi (and especially the VCL components from Delphi) just don't have what you're looking for. Yet, you know that it can be done; since this other application is capable of calling the right function(s) and do what you seemingly can't...
The goal of this session is to show that Delphi and the Delphi VCL does indeed not cover the entire Win32 API, nor does it come close to cover the additional libraries (DLLs with header files) and SDKs that seem to be released every month now. However, instead of sobbing over this lack of functionality, we'll find out in this session that life isn't as bad as it looks like (or at least Delphi's Win32 life), as we plunge into the Win32 API head first and get our hands dirty the hard way...
We start off relatively easy, by exploring how to achieve some stuff not catered for by Delphi's VCL code. Examples shown during the session include:
executing other applications
using the ShellExecute (easy) or CreateProcess (more complex) APIs, we can execute foreign applications from our Delphi programs.
At times it would be handy not only to start other applications, but to stop them as well. Or close them, kill them, or terminate them, whatever you want. We'll see numerous APIs to close applications, including Windows itself.
obtaining system information
sometimes it's necessary to obtain system information; from the amount of free disk space and resources to a list of current available Windows, etc. We'll see a number of APIs to assist in this task.
Delphi support exceptions, but whenever we interact with the Win32 operating system, other errors are bound to happen. We'll see which error APIs are important to keep in mind when playing with Win32.
2. Extending VCL
After we've played with some of the native Win32 APIs, it's time we swim back to the VCL and see how we can "extend" some of the VCL components in ways that are only possible by "playing" with the Win32 controls behind the scenes. Examples of extended controls and control behaviour shown during the session include:
Windows itself does not support the (right) alignment property of a single lined editbox. But this control would be so convenient to use when displaying numerical data, for example. So we can make one, by invading the control underneath, and making it "think" it's a single line, right aligned editbox.
3. Importing DLLs
When we done swimming around in VCL extended controls, it's time to get ashore and look around for those numerous custom APIs and SDKs out there that are not supported by Delphi. By not supported I mean: APIs and SDKs that (usually) ship as a set of C DLLs with C header files. And no Delphi import units, yet.
In order to "support" these APIs and SDKs, the "only thing" that has to be done is converting these C DLL header files to Delphi import units. This is a complex task. Fortunately, there is a group of volunteers, called the Delphi JEDI group, who's dedication is to produce Delphi import units for most API/SDKs available.
Apart from the Delphi JEDI group, I'll also show a tool called HeadConv, capable of automatically performing a first-pass conversion of the C DLL header file to a Delphi import unit (about 85% conversion ratio - but you still need an expert hand to finish the job).