Wednesday, July 27, 2005


Various and sundry

HELO blog readers!

Haha, just kidding! I have no readers. I can't prove that without violating the Heisenberg uncertainty principal though.

ANYHOO... I've been meaning to update with a wrap-up from vacation. You know, because I was blogging every day and then, stopped. That's nothing new from me, but I should make some notes about how things turned out and all... Basically they turned out great. I posted a few times about the meaning of the word "Aloha". I'm the stupidest of haole but I have at least a basic inkling of the real meaning of the word. You know, the way we (tourists) abuse the word aloha is really symbolic of the way the west has abused Hawaii as a whole. The simplest way to think of Aloha and Mahalo are as a thought and a blessing. Aloha, to me, means we are brothers and I love you as myself. Mahalo I think of as the highest prayer of goodwill/good fortune. These words are incredibly sacred and powerful words, and the foremost representatives of a really cool philosophy. I miss Hawaii. It has definitely been added to the "places to live" list, although that's tempered by a few things. I don't want to be a net negative to the local infrastructure, etc (Oahu in particular is getting full).

After Hawaii was California. I got over the cold in San Francisco but not soon enough to enjoy it. I remember a meal at a little Italian restaurant with Tracey's uncle Michael (really nice fellow). I was eating soup to try to stop my nose from running constantly. In order to eat the soup, I set aside my cough drop which was the only thing preventing constant coughing. I probably made a worse impression than normal.

LUCKILY, I did get better in time to have a fun visit to the Jelly Belly factory. I took the tour and bought some rejected candy. Those things are ridiculously good.

Spent a couple of days in LA. The throughways are complicated, even with a nav system. I didn't like Rodeo Drive (I am prejudiced against rich people). I did do a studio tour at Warner Brothers which was interesting (but expensive). I'm sure I'll visit California again.

Shuttle launches. I have tried twice to see the launches. The first time got scrubbed. I went out to today's attempt with good intentions only to get shafted by my own stupidity. I stupidly assumed that 2 hours leeway would be enough. I only got to within 11 miles of the intercoastal in that time. My view of today's launch was of everyone on the beeline pulled over with their radio's on looking at NOTHING. On the way home, I took highway 50 which was much faster. Found out that people at work had a much better view than I did. Next launch I'm taking a vacation day and doing this properly.

An unrelated thought on the "3-tier pattern": I'm working on an app at work that is using a different pattern. It's more of a 4 tier pattern, and the business logic is totally abstracted from the database engine. The UI talks to a component that talks to the database and is connected to the business logic. The database is used to populate objects (via NHibernate). These objects are sent to a blind business tier. Typically it's the other way around - the UI talks to the business tier which is fully aware of and talks to a database tier. I may post a diagram. I'm very new to this programming stuff but this way seems more encapsulated. It may be more common when O/R mappers are in use. Also, there are some patterns that come in handy when the business tier needs database access, such as for logging normal events (aside from exceptions) and I may post an example of that as well.

Monday, July 11, 2005


Getting a shortcut's target in C#

The .NET Framework has a lot of handy classes but none that read a shortcut's target. Normally you can add a reference to Shell32, instantiate it, NameSpace over to the shell link hoo-hah and read the target. I couldn't get this to work for a UNC path in an ASP.NET application without changing the account listed in the application pool. I found a doc that has the file format and wrote a method for reading the data I need:

private string GetShortcutTarget(stringfile)
// Based on shortcut file format documentation by Jesse Hager.
// This reads paths for local files. It would need tweaking if the shortcut
// pointed to a UNC.
if (System.IO.Path.GetExtension(file).ToLower() != ".lnk")
throw new Exception("Supplied file must be a .LNK file");
FileStream fileStream = File.Open(file,
FileMode.Open, FileAccess.Read);
using (System.IO.BinaryReader fileReader = new BinaryReader(fileStream))

// uint constant = fileReader.ReadUInt32(); // Reads the letter "L"
// byte[] guid = fileReader.ReadBytes(16); // Reads the GUID - another constant
fileStream.Seek(0x14, SeekOrigin.Begin); // Seek to flags
uint flags = fileReader.ReadUInt32(); // Read flags
//Results.Text += "<br>" + flags.ToString("x") + "<br>";
//Results.Text += "uflags & 1 = " + (uflags & 1) + "<br>";
if ((flags & 1) == 1) // Bit 1 set means we have to skip the shell item ID list
// Seek to the end of the header
uint offset = fileReader.ReadUInt16(); // Read the length of the Shell item ID list
fileStream.Seek(offset, SeekOrigin.Current); // Seek past it (to the file locator info)
long fileInfoStartsAt = fileStream.Position; // Store the offset where the file info
// structure begins
uint totalStructLength = fileReader.ReadUInt32(); // read the length of the whole struct
fileStream.Seek(0xc, SeekOrigin.Current); // seek to offset to base pathname
uint fileOffset = fileReader.ReadUInt32(); // read offset to base pathname
// the offset is from the beginning of the file info struct (fileInfoStartsAt)
fileStream.Seek((fileInfoStartsAt + fileOffset), SeekOrigin.Begin); // Seek to beginning of
// base pathname (target)
long pathLength = (totalStructLength + fileInfoStartsAt) - fileStream.Position - 2; // read
// the base pathname. I don't need the 2 terminating nulls.
char [] linkTarget = fileReader.ReadChars((int)pathLength); // should be unicode safe
string target = new string(linkTarget); // convert the character array to a string
return target;
Edit: I'm glad this code is getting some use. Please consider it public domain, but bear in mind that I make no warranties about the fitness or merchantability of this code for any particular use or purpose. Apologies about the crazy formatting. If it works for you feel free to email me:

This page is powered by Blogger. Isn't yours?