Almost ADSL
Posted on 2 Jul 2002 at 17:04
Dave Jewell awaits his ADSL installation with both fear and excitement, and shows how to access the Shell32 COM objects from C#
if (item.IsFolder) FList.Items.Add ("-" + item.Path + "-');
else FList.Items.Add (item.Path);
}
}
}
As you can see, the code iterates through the various files in the folder, adding each one to the list box. If NumFiles happens to return zero (an empty folder), then the semantics of C# ensure that the for loop never executes and the list box remains empty.
You'll also notice that I use a property of the FolderItem object, IsFolder, to determine whether or not each folder item is itself a folder. If so, I enclose the folder pathname within hyphens which - because the list box is kept sorted - ensures that all the folder names are placed together, followed by the ordinary filenames (though, of course, this simple scheme will screw up if you happen to have any ordinary files whose names begin with a hyphen). If you want to do the job properly, use an owner-draw list box and apply distinctive formatting to the drawing of folder items. Likewise, if you wanted to display things like file size and modification date alongside each item, use a list view control operating in report mode rather than a simple list box. I should also point out that .Net contains its own set of rich classes and methods for manipulating files and directories - all I'm trying to get across is the simplicity of accessing COM objects from a .Net application.
Another interesting method of the Shell object is ControlPanelItem. Just pass the name of a Control Panel extension as an argument to this method and - hey presto - it will be started for you.
sh.ControlPanelItem ("desk.cpl");
In this example, the desk.cpl extension will start executing, showing the familiar Display Properties dialog. Note that if the specified extension is stored in the Windows or WindowsSystem directory, it isn't necessary to provide a full pathname, but the cpl file extension isn't optional.
The EjectPC method can be used to eject a laptop PC from its docking station, while the more useful Explore method will invoke Windows Explorer, set to a designated folder location:
sh.Explore ("c:Program Files");
The FileRun method can be used to invoke the Shell's Run dialog (equivalent to clicking 'Run...' on the Start menu), while the FindFiles method invokes the standard Find Files dialog, and so on. Many more interesting things can be done by referencing the Shell32 library from a .Net program and this is one of many COM objects that Microsoft makes available.
Exemplary decompiler
I pointed out a few months ago that the IL code used by Microsoft .Net is very easy to decompile. This is because this virtual machine code is stack-based, which means that any prospective decompiler doesn't have to worry about keeping track of machine registers. Likewise, because the IL codes are relatively high-level operations, the amount of work needed to produce an equivalent high-level language representation is correspondingly reduced. All the same arguments apply to Java byte code, which has been plagued by decompilation almost since its inception.
As I wrote about the possibility of a .Net decompiler, I didn't realise how quickly my predictions would be fulfilled. Let me introduce you to Exemplar 0.1, the world's first (as far as I know) full decompiler for C#. You can find Exemplar at www.saurik.com/net/exemplar and impressive it is too. Exemplar is freeware, released under a GPL licence and comes with full source code written in C++. The program isn't perfect, as it crashes when it comes across a chunk of IL code that it doesn't understand, and it currently exists only as a command-line utility. But as a proof-of-concept application, it's amazing.
From around the web
advertisement
- Chrome's shine getting lost in translation
- BytePac: the cardboard hard disk enclosure
- How tech loosens our grip on reality
- Hokum watch: Safer Internet Day
- Why I'm deleting Adobe from my PC
- Prepare to be patronised: it's Safer Internet Day
- Dear Sony, Samsung and every other tech company in the world: stop trying to be Apple
- Will Apple's Final Cut Pro X update placate the pros?
- Smartr Contacts for iPhone review
- Switching to Office 365's Outlook Web App
- Ofcom dithers over plans to tackle broadband slamming
- Speed-hungry customers push Virgin into profit
- Ofcom to impose price cuts on BT line rental
- Virgin hikes prices after "free" upgrade
- BT to offer 300Mbits/sec fibre "on demand"
- Ofcom outlines plans for wider 4G coverage
- Virgin upgrade to double broadband speeds
- Satellite broadband "being ignored"
- Sky blocks Newzbin over copyright claim
- Push to get more people online stalls
advertisement
