Longest monday ever

Forgive the back postings (there will be more) but I recently went on a business trip and I want the post dates to match up with the actual.

Wildpalms hotel in Sunnyvale California

Today was the longest monday ever. Started as per usual by getting up and having breakfast. Filled in the rest of the morning by doing some preparatory work followed by lunch. Worked for a couple more hours then grabbed a shuttle to the airport. Checked in, waited for plane, got on plane, ate, watched movies, slept, ate, landed at San Francisco International, disembarked, and cleared customs. There was a bit of confusion over who was picking up who at the airport; eventually someone turned up to take me down to Sunnyvale where I checked into the hotel. From there I was taken into the US office in Santa Clara and worked the afternoon. Had a quick dinner at El Torito followed by sweet sweet sleep.

All on a monday.

/clr and nonmanaged libraries

With Visual C++ mixing managed and unmanaged code is always interesting. It either just works, or your application dies horribly before reaching the main entry point. Debugging in the pre-main world of static data registration and atexit handlers is not very fun. Fortunately a post made by Jeffrey Tan of Microsoft Online Community Support provides a solution:

By further discussing with a developer from VC++ team, he confirmed that
this was a known issue. The main problem here is that the IDE is specific
the entry of ManagedApp as “main”. However, using “main” will bypass a lot
of CRT’s startup initialization. The fix here is to simply change the
entry point in the IDE. Under ManagedApp -properties-link -advanced,
change “entry point” from “main” to
“?mainCRTStartupStrArray@@$$FYMHP$01AP$AAVString@System@@@Z”. That should
re-enable the CRT startup code which initializes the internal CRT variables.

Original discussion can be found here.

[c++] Sneakily updating base classes

Recently I needed to update data in a base class, but only for types derived from that class.

struct Base {
	void Func() { cout << "Base::Func calledn"; }
};

struct Child : public Base { };

struct AnotherStruct { };

For example I want to call Base:Func() for all types that have been derived from Base. In the code above this would include Child and Base, but not AnotherStruct. If I've been given AnotherStruct then I don't want to do anything.

void call_base_func( Base* base ) {
	base->Func();
}

void call_base_func( void* ) { }

Thanks to function overloading this can be solved easily. Passing a Child to call_base_func will result in the first function being called, while AnotherStruct will use the second function.

But what do we do if Base is using the Curiously Recursive Template pattern?

template 
struct Base {
	void Func() { cout << "Base::Func calledn"; }
};

struct Child : public Base { };

struct AnotherStruct { };

Well now the type of Base is dependent on the type of Child. This breaks our previous solution as we can't specify Base without also specifying a type. Or can we?

template 
void call_base_func( Base* base ) {
	base->Func();
}

void call_base_func( void* ) { }

Sure we can. If Base is going to use templates, then so can call_base_func. As an added bonus we also get the type that initially derived from Base.

-

An example of this technique is with smart pointers. More specifically if you have a look a Boost shared_ptr it provides an enable_shared_from_this base class. This class tracks references to the derived object and allows you to acquire a corresponding shared_ptr to that object. The only way this can function is if the shared_ptr class can update the internal data in enable_shared_from_this, and only when the type is derived from enable_shared_from_this.

I just waxed the bathroom

Having just finished cleaning the shower I return to the sink and refill my bucket for the third time. While watching the water slowly creep up the sides of the container, I reach for the generic cleaning concentrate I’ve been using. I stop. Something has changed. Something is different. Something is wrong. Snatching up the concentrate I turn it over. Wash ‘n wax. Crap.

Perhaps keeping all the cleaning supplies in the one place was not the best idea.

Application updating

In a previous post I suggested an application which would centralize and manage software updates. While not quite what I envisioned; File Hippo does a good job. There’s even an update checker tool which will scan your local system and let you know if newer versions of supported software are available.

[c++] Cross thread communications – Part II

Recently I’ve been playing around with managed C++ and the .net framework. As usual I have one thread wanting to instruct a separate GUI thread to perform some task. In .net world with the help of delegates (glorified function pointers) this behaviour is easy.

First define the function to call:

///  update text box text from another thread
void MyGuiClass::updateText( System::String^ text ) {
	// show text
}

then define a delegate:

public delegate void GuiUpdateTextDelegate( );

and finally invoke the delegate from another thread:

BeginInvoke(
	gcnew GuiUpdateTextDelegate(
		this, &MyGuiClass::updateText, gcnew Systen::String("new text")
	)
);

While I’ve used BeginInvoke here, you should be aware that there is also an Invoke method. Invoke will wait until the delegate has been invoked, while BeginInvoke won’t and is asynchronous.

Bacteria v0.14

While showing off my screen saver today I discovered that Bacteria doesn’t support multiple monitors… or should I say didn’t. The fix entailed reading the release notes to discover that the change had already been made! Somehow the newer version had never been officially released, and left sitting on my hard drive for several years instead. This has now been rectified.

You can download Bacteria v0.14 from my programs page.

Onwards and upwards

Early last week was my last day at Day One. While it has been fun, it was really time to move on. Now I’m going to cheat and just paste in the email that I sent everyone (in the event that you missed it, and you actually read this site):

As you are probably aware, today (6th March) is my last day as an employee of Day One Digital Media Ltd. This decision did not come easily, but I do feel that it is time for me to move on. Although I won’t be here for the remainder of this week, I most likely will be back next week on a part time contracting basis. My current plan is some local contract programming with the possibility of an O.E. later in the year.

I will miss all the great employees and excellent customers. Each of you have taught me something new and shown me new ways to go about solving old problems. I can only hope that I have given back as much as I have taken. There are very few software programming jobs where you get to climb around cabling large structures in the dark. Although I never did reach my three double panel quota…

Thanks again, you’ve been great

Eaarrtthhqquuaaakkeee

Woa, just felt an earthquake about twenty minutes ago. What’s unusual is that this is the first earthquake I’ve experience in Auckland… ever.

“The earthquake, which measured 3.7, hit at 9.02pm, and was felt throughout the Auckland area”The NZ Herald