December 2010 - Posts

Hangklip throws Win32Exception: File not found

At least one commenter wondered if this still is a developers blog or just a personal whereabouts chitchat. It is both. And although this blog is going to present some code at last I wondered for a moment what would happen if I obfuscated all the logical names in the code to famous tourists attraction like Cape Town, TafelbergCape Alguhas and the majestic Hangklip. Maybe three blogs of chitchat is enough for most readers, pity.

On a small project last week I encountered an issue when I needed to launch an windows application. In my mind the solution was pretty simple, instantiate the Process class, supply it with a ProcessStartInfo, call Start(); and you’re in business.

The first test run however ended in an Win32 Exception: File not Found. I’m still partly human so mistakes come natural. The command prompt was quickly started and the dir “c:\Windows\system32\filename.exe” showed immediately….that the file did exist, it even had a size, and when I ran the file it actually showed what I expected.

Puzzled I reverted back to the code, verifying that  I was indeed providing the correct path and that ProcessStartInfo had the correct settings and arguments. Google pointed out that there are issues when you want to run a 64bits exe from a 32bits process. Could that be the case: I was on Vista x64, building a .Net 4.0 commandline app, targeting x86 from within Visual Studio 2010. The executable I wanted to launch was the Backup and Restore app, sdclt.exe. On disk it resided in the Environment.SystemDirectory (“c:\windows\system32”). The reason it refused to start/to be found lay in the Windows on Windows functionality. WOW is a concept that I first encountered in the form of win32s (yes, I’m that old). It automagically let you run apps compiled for an other number of bits on the same box. One of the features of WOW is to redirect file access in system32 to SysWow64, without the user ever knowing it. Great, and now disable that.

You could recompile to x64 and you’re done. If that is not possible you might find this little class help full. It tries to determine as good as it can if the executable you want to launch is a 64bits PE file. I use the GetBinaryType api for that. Once that is determined a call to Wow64DisableWow64FsRedirection (the microsoft employee responsible for coming up with decent short names for API’s was an holiday) disables redirection and therefor a call to Process.Start() will succeed.

For convenience (or over engineered) I extended the Process class and abstracted the disabling and enabling in a helper class that implements IDisposable. Leveraging this class becomes as easy as this:

ProcessStartInfo restoreBackupProcess = new ProcessStartInfo(
                Path.Combine(Environment.SystemDirectory, "sdclt.exe"), 
                @"/RESTOREPAGE");

ProcessEx pe = new ProcessEx();
pe.StartInfo = restoreBackupProcess;
pe.Start();
pe.WaitForExit();

The Start(); method will always succeed either if the windows executable is 64bits or 32bits.

The new Start() method looks like this:

    /// <summary>
    /// ProcessEx extends Process to Start 64bits system exe's from a 32 bits process
    /// </summary>
    public class ProcessEx:Process
    {
        /// <summary>
        /// Overriden Start method
        /// </summary>
        new public void Start()
        {
            // we can only start if we have a StartInfo
            if (this.StartInfo != null)
            {
                // Disable WOW64 redirection if needed
                using (new DisableWOW64(base.StartInfo.FileName))
                {
                    base.Start(); // real start
                }
            }
        }
       ....
     }

Have a look at the full source code for the DisableWOW64 implementation.

Posted by Rene Schrieken | with no comments

South Africa, the conclusion

Now that I’m back in the Netherlands for over a week it is time to make up the final verdict of the wine lands, Western Cape, South Africa. One thing is for sure: Cape Town and it’s surroundings offer great places to stay. You already know Bezweni Lodge from my previous post but if they are fully booked check here for other accommodations. When you stay at Bezweni Lodge I can recommend this appetizer: an 11 km walk on the Knorhoek estate.

knorhoek-map

And the accompanying GPS Track.

Although I didn’t really visit Cape Town (only did a drive through to some of the hikes) I did visit some lovely towns. For culture go to the university museum in Stellenbosch and for some great history on the barbarian Europeans go to the Huguenot Museum in Franschhoek.  In both cities you can have fantastic lunches which combine beautifully with the lovely wines.

And then near Gordons Bay, Strand has the best beaches, accompanied by some very fine seafood restaurants. Don’t forget to ride a horse in one of the high riding stables around Sir Lowry’s Pass. They will  bring you to a wine farm and it will become easy to taste every single wine and get very drunk before you get back on/besides the horse.

Here are the highlights in photo’s:

Paarl, Taalmonument and the top of Paarl mountain

i-was-here

Some impressions of my hikes: Helderberg Nature Reserve and the top of Leopardskloof in Harold Porter Botanical Garden.

Wildlife: Struisvogels and Penquins

Flowers: Paperflower and Sundew (Zonnedauw, breedbladig)

Just tourist: Cape of Good Hope (most south-western point) and Cape Agulhas (most southern point)

Top two: Sunset and the Panorama Trail in Jonkershoek Nature reserve (profile)

pan-trail-profile-sml

And then to remember that this was just the western cape. There is so much more to see, visit, experience. Message to self: plan holiday for the remainder of South Africa…

The BIG 5!

I've done the big 5. This is off course important if you are visiting South Africa. I had my big 5 planned with a couple of days between so I would have time to overcome the bewildering experience and recover enough to be up for the next in row.

You can't safely claim you' ve completed the big 5 without a guide or you will end up in indentifying 2 scuba divers as seals landing on the beach. Preventing this type of screw ups was Binny. A wonderfull women that stirred me clear of any mishaps. Above all she was keeper of the coffee break and lunch rucksack. Somehow she was able to keep pulling out food, snacks, selfbaked cake, fruit and liquids that you wondered once on display how it fitted in the rucksack in the first place. 

As you all know it is best to synchronize your watches with nature, which basically ment that I had to rise at six, drive at seven and arrive at an rendezvous point at eight. Nature doesn't wait and don't like anybody calling in late.

The first planned encounter was a famous and nerve-braking one: Maclear's beacon on top of Table Mountain ( I guess you get a hint now where this is going to. Wait till you read about the elephant). Although I made some decent walking kilometres in the Netherlands the going-up muscles gets never trained. And you'll start to feel them when you climb-up Skeleton Gorge. When you arrive at the top an stroll in the park gets you to the eastern table where you find Maclear's beacon, the highest point of Table Mountain. (To be clear: That is NOT where the cable car ends). The down route followed the Platteklip gorge and the hike ended at the lower cable station.

Here is the prove (and the only "i was here" photo):

Table Mountain is not just an handy hook to attach the cables of the cable car to, it is an enourmous mountain, consisting of several rock formations. Second encounter with Table Mountain had to be with the Twelve Apostels on the west side of the mountain facing the atlantic. Going up this time via Kasteelpoort (One reason I love the country is the dutch words you can put in whenever you want and still everybody understands what you're saying). After reaching the plateau we hiked to the waterworks museum. Finding a steam train at the top of a mountain is still akward.

As I said earlier you need some time to recover, specially from going up and down over and over again. To break-away from the daunting table mountain massiv the third hike is a river hike. The Palmiet river in the Kogelberg nature reserve. Starting at the Kleinmond side of the river a cozy path lines the river. Everybody can do this hike, even if you more like a beach lover.

On the beach you might detect all kind of wild-life that occupies the nature reserve. Binny pointed out Fish Otter, Small antilope and even a leopard left it footprints in the wet sand on the beach. When you push on you are rewarded with beatifull sights and a real sense of remoteness as even the cell-phones lose connection.

 Fourth in row was the so called Panorama Trail. Layed out in the Jonkershoek Nature Reserve just west of Stellenbosch. The Panorama Trail gets you in a circular route rather gently up hill and then fiercly down at the "kurketrekker"  (corkscrew). On this hike the over-warned snake danger popped up. First on the road a puf-adder was trying to get its body temperature too such level that it could start moving and later at the day early-warning system Binny warned (others on the hike made different comments) everybody for a snake. As this one had laying baking in the sun wholeday it definitely went in attack mode. Animals nor woman where hurt in the accident.

Ending my BIG 5 experience was at Cape of Good Hope. Although full of wild things (baboons, but aboveall homo sapiens) it is still posible to have a good hike there. On the way you can admire the new and old light house, men on wooden shoes, fynbos, and a wide variety of birds. The wind was very, very mild for december at the cape so the experience was awesome.

On the next photo you can clearly spot the blue touched sapiens, hugging the hill.

 And last but not least, as promised, the elephant:

 

Western Cape

As hell is freezing over in western europe I felt it would be appropiate to cheer you up with a small post from Sir Lowry's Village. If you're wondering where that might be, it is just around the corner at Cape Town, South Africa. I'm staying at Bezweni Lodge, an absolute stunning place. A few reasons: The dirt road (which only adds to the growing expectations), the wide views, the lovely landlady, the scenery, the fantastic room, the wonderfull breakfast, and last but not least: Dinner!

If you are planning to visit the western cape around cape town, Sir Lowry's Pass Village is a perfect basecamp. You'll reach the main attractions easily, whether you're into hiking, tatsting, riding, diving, shopping or culture and history.

Just to give you an impression:

Sunset:

 

Fresh Seafood (not eaten by me)

 

 

Posted by Rene Schrieken | with no comments