The Weekend, planning is always unadvisable.

As always, planned things never go to plan. It’s a rule that I now have come to accept, it doesn’t apply to everyone, but certainly does to me. So Saturday morning my sister and I were due to get up reasonably early and head off to Farnham to visit our Grandad who had just got out of hospital. Sounds quite simple. Had planned to catch a train from Waterloo around 10am, which means leaving Dalston about 9am to give time to get tickets etc. Wake up roughly around 9:30am, completely forgot to set any alarm what so ever. Slight panic… oh well catch the next train. Get ready, check have everything, erm… where’s my Network Card?!? … erm sure I had it the other day (also contains the Oyster for the bus). No not in any of the usual places (various points on the floor), half an hour later and my room in near ruin, nope definately not here. Hmmm, it’s got to be at work then. Arse, so I get on the bike and cycle down to work, get to the office door, shit, forgotten the combination code to get in. Embarrased call to colleague, I’m in. Found pass quite quickly, left work, bugger I forgot to leave the bike locked in the office, unlock fort knox, relock, leave. Would you adam and eve it there are no bloody buses. Eventually one turns up and we make it to Waterloo several hours later than planned. Turn up in Farnham some time after lunch and end up having a very nice afternoon with Gran and Grandad.

The rest of the weekend (un planned) went ok. Caught the Dad-Taxi back to Southampton to catch up with some friends at local BBQ. Not a huge turn out but it was nice evening and spent most of today (Sunday) enjoying the sun. Rigged up some speakers in the garden and listened to woxy on the itouch. Feeling a bit rosey so suspect mild burning, always get caught out by the first lot of decent sun. On the train now back to London.

Make the Pogues #1 this Christmas

I was watching the news this morning and this bloke from HMV came on to give his view on who was going to be number one at Christmas. Now aparently for the last few years since its evil inception the X-Factor singles have on average got sales in the region of 100’s of thousands over [...]

Creating threads

June 18th, 2009

I struggled with this concept for a while so thought I would write a little post about it.

Is it possible to create a multi-threaded application in Visual C++ Express, which lacks ATL and MFC library support.

The answer is yes, you use the CreateThread API call and here’s how:

Make sure these headers are included:


#include <windows.h>
#include <stdio.h>

Now create your thread function, this function is what gets executed by the CreateThread API call. In my example I want to pass an object to the thread and then do something with it. In my case I am invoking my objects load function.

DWORD WINAPI LoadObject(LPVOID lpParameter)
{
MyObjectType* f;
f = (MyObjectType *) lpParameter;
f->load();
return 0;
}

Now we’re ready to create our thread from within our main code…


DWORD dwThreadId;

HANDLE hThread = CreateThread(
NULL, // pointer to security attributes
0, // initial thread stack size
LoadObject, // pointer to thread function
(LPVOID)&f, // argument for new thread
0, // creation flags (immediate)
&dwThreadId // pointer to receive thread ID
);

if (NULL == hThread) {
// error reporting here
exit(1);
}

// for example purposes, wait for the thread to complete and each second until it does print a '.' to the console.

while(TRUE) {
if (WaitForSingleObject(hThread, 1000)==WAIT_OBJECT_0) break;
printf(".");
}

// You then need to close your handle to the thread with

CloseHandle(hThread);

// That's it, obviously a very simple example and you will want to be creating multiple threads simultaniously etc.