Sunday, December 29, 2013

Refreshing or Rebuilding ShellIconCache

Here is a simple command line app to rebuild or refresh your Windows ShellIconCache. You can run it by just double clicking on it as it does not accept any command line parameters. Tiny Delphi source file is included.

Download RebuildShellIconCache.rar (50 KB)

Saturday, May 11, 2013

Sending email with attachments using C# and Gmail

Sending email with .Net is far simpler than it is in Delphi (using Indy).

Put the following in your classe's "using" section:
using System.Net.Mail;
using System.Net;

Include this method in your class

        private bool SendViaGmail()
                var client = new SmtpClient("", 587)
                    Credentials = new NetworkCredential("", "mypassword"),
                    EnableSsl = true
                var msg = new MailMessage("",
                    "Email subject",
                    "This is the email body...");
                msg.Attachments.Add(new Attachment("1.txt"));
                msg.Attachments.Add(new Attachment("2.jpg"));
                return true;
                return false;

Sending email with attachments using Delphi, Indy 10.5.5 and GMail

Sending email using Delphi is not difficult, you just need to know the carious bits and pieces that go together to make it happen. Over the years Indy has changed its classes and methods so your version of Indy might function slightly different to mine, Indy 10.5.5, its just the one that I have to hand right now. I'm also using Rad Studio 2010. To send email using GMail and Indy you'll need to download the Open SSL libraries. This is because GMail sensibly requires a secure connection while sending, and also receiving email.

You can download the Open SSL libraries here: (32-bit builds only at time of writing). You need to place 2 of the files contained in the download (libeay32.dll, and ssleay32.dll) into your system's path or just place them into the same directory as the executable you are building/running. Now for the Delphi part.

Saturday, December 29, 2012

If its not a Google Nexus, it's already obsolete

It pisses me off that the only way to guarantee that you are running the latest version of Android is to own a device that Google designed and coached through the production process. Google do a great job, don' get me wrong. However if you use Samsung Galaxy S3 or HTC device, you have a really nice but out of date device experience. The crapware that manufacturers and carriers put in their Android devices (HTC Sense and Samsung overlay, as well as carrier alterations) slow down the process so much that it make stock Android the only feasible choice.

Saturday, July 21, 2012

Mobile OS Updates - Manufacturers gouging customers

I'm done with HTC, Samsung and Nokia. The seeming never ending wait for OS updates from device OEMs is a pain in the ass. In the last few years I've owned phones from all 3, and felt like a sucker when they announce that to get the latest OS you need to buy a new device. Fuck that.

The straw that brok the camels back is my Nokia Lumia 800. Microsoft pretty much called all owners of Lumia 800 and 900 handsets morons by announcing that Windows Phone 8 will not be released for them. Instantly making that product line a worthless zombie product line.

And as for buying an iPhone. Nah. I don't really feel like being laughed at by my phone maker. The only way to ensure a satisfactory update roadmap for your device and not be ripped off in the first place is by buying a Google Nexus phone. End of story.

Sunday, November 6, 2011

Microsoft's 1999 Homepage. Disingenuous Much?

Check out Microsoft's homepage from 1999 and Bill Gate's apparent concern with privacy and security. lol. The veritable orgy of ball-dropping since then defies belief but back then using the right business "e-speak" was all you needed to convince people you had things under control.

See also the link to the propaganda piece entitled "Microsoft and the freedom to innovate" along with the gavel symbolizing the DoJ's oppression. Freedom to innovate seemingly meant Windows ME, ActiveX, a web browser that was essentially an open telnet server. This of course was around the time Microsoft was being dragged through the courts in the US for being an anti-competitive monopoly. They eventually settled with the DoJ by offering to give free software licenses to schools and certain  non-profits, thereby further increasing their market share. Go figure.

Asp.Net Session variable not set on Redirect()

In Asp.Net, when you want to set a Session variable then immediately do a Response.Redirect(), the Session variable gets lost, like it was never set. Asp.Net has an overloaded version of  Response.Redirect() that, as well as a destination URL, it takes a bool that tells Asp.Net whether to end the thread or not.

By default, calling Response.Redirect(string Url) will terminate the response thread, meaning your session variable will not get set, only the redirect header gets sent to the client. Use something like this instead.

Session["somevariable"] = "some value";
Redirect("http://whatever..", false);
//Rest of code gets executed

C# Image Watermark (Overlay) Example

It's often a good idea to stamp your own photos or images with your mark when distributing on the internet to discourage people from claiming them as their own work, or in case they just forget image attribution.

NOTE: This is an over simplified piece of code and is missing some functionality like
  • Image resolution syncing (ensuring base and watermark images have the same dpi). Otherwise the watermark could end up being stretched compared to it's native view.
  • Boundary checking (check that watermark is totally inside the base image).
  • Watermark transparency. A fully opaque watermark can distract from the content of the base image, or just look ugly. Transparency blends the watermark into the base image creating a nice effect.
  • Rounded watermark corners. Rounded corners are cool right so yeah gotta have them too.
A more comprehensive class to achieve these is available in my open source C# library BFLib hosted at Google Code:

Here is the simple piece of code that overlays one image on top of another:

//_baseImage is the photograph/image you want to put a watermark on
Bitmap _baseImage = new Bitmap("c:\myphoto.jpg");
//_stickerImage is ususally a small image with your logo or name.
Bitmap _watermarkImage = new Bitmap("c:\mystamp.jpg");

//Draw the watermark offset 10 pixels from the left and 10 pixels from the top of the base image.
Graphics canvas = Graphics.FromImage(_baseImage);
new Rectangle(10, 10,
_watermarkImage.Width, _watermarkImage.Height),


Saturday, November 5, 2011

Google Chrome extensions - deal breaker dialog

Recently I've been looking at installing some Google Chrome extensions to speed up certain tasks. Browsing through the extension repository or "Chrome Web Store" I found that the extensions are divided into 2 types. The first is a bookmark type, that just add a link to your new blank browser tab. Nice and simple but not super useful. Then the more useful type that always seem to display this deal-breaker of a dialog box before installing. (This TinEye dialog is used just as an example).

A pretty typical extension installation dialog

Access to my data on all websites? Why? Why do extensions that have no need to access my browser history need access to it? This is either a serious browser deficiency or lazy extension developers who have never heard of the Principle of Least Privilege.

Thursday, February 10, 2011

Amazon Simple Email Service (SES) C# Code Example

Amazons Cloud guys have been busy recently. Their new service Simple Email Service (or SES) has gone into beta and seems like a winner for people who spend a lot of money on mail-shot services and would like to take some control. Assuming you have already signed up for AWS and generated a new access key pair, you should download the new AWS .Net SDK here.

You need to sign up to the service by optionally entering a VAT number associated with your business. Next you need to enter your telephone number and submit, almost immediately you will receive an automated phone call that lets you enter a 4-digit verification code that is displayed one you actually submit your phone number. All fairly painless and quick.

As the service is in Beta you cannot just email anyone using the service right now. You must verify each "from" email and each "to", "cc", or "bcc" email address. But the AWS SES FAQ located here: seems to indicate that this will change.

Friday, December 31, 2010

ISO/FIPS, FIPS/ISO Country Code Conversion Classes

I've just completed a simple pair of static C# classes to convert between ISO (3166-1-alpha-2) and FIPS (and vice versa). You can access the source code using Subversion or just browse it here There are of course many ways to do it but the emphasis here is on speed.

Saturday, November 13, 2010

Delphi: Get system icon handle

Delphi function to retrieve the icon handle of a system resource. 

uses ShlObj;
function GetSystemIcon: HICON; 
  FileInfo: TSHFileInfo;
  PIDL: PItemIDList;
  SHGetSpecialFolderLocation(Application.Handle, CSIDL_DRIVES, PIDL);
  if SHGetFileInfo(PChar(PIDL), 0, FileInfo, SizeOf(TSHFileInfo),
        Result := FileInfo.iIcon;
Constants defined in ShlObj.pas

  CSIDL_DESKTOP                       = $0000; // 
CSIDL_INTERNET                      = $0001; //Internet Explorer (icon on desktop)
  CSIDL_PROGRAMS                      = $0002; //Start Menu\Programs
  CSIDL_CONTROLS                      = $0003; //My Computer\Control Panel
  CSIDL_PRINTERS                      = $0004; //My Computer\Printers
  CSIDL_PERSONAL                      = $0005; //My Documents
  CSIDL_FAVORITES                     = $0006; //user\Favorites
  CSIDL_STARTUP                       = $0007; //Start Menu\Programs\Startup
  CSIDL_RECENT                        = $0008; //user\Recent
  CSIDL_SENDTO                        = $0009; //user\SendTo
  CSIDL_BITBUCKET                     = $000a; //user\Recycle Bin
  CSIDL_STARTMENU                     = $000b; //user\Start Menu
  CSIDL_DESKTOPDIRECTORY              = $0010; //user\Desktop
  CSIDL_DRIVES                        = $0011; //"My Computer" folder
  CSIDL_NETWORK                       = $0012; //Network Neighborhood (My Network Places)
  CSIDL_NETHOOD                       = $0013; //user\nethood
  CSIDL_FONTS                         = $0014; //windows\fonts
  CSIDL_TEMPLATES                     = $0015; //Templates folder
  CSIDL_COMMON_STARTMENU              = $0016; //All Users\Start Menu
  CSIDL_COMMON_PROGRAMS               = $0017; //All Users\Start Menu\Programs
  CSIDL_COMMON_STARTUP                = $0018; //All Users\Startup
  CSIDL_COMMON_DESKTOPDIRECTORY       = $0019; //All Users\Desktop
  CSIDL_APPDATA                       = $001A; //user\Application Data
  CSIDL_PRINTHOOD                     = $001B; //user\PrintHood