Date Driven Development (DDD)

October 30, 2009 by boycook

I tweeted this as a joke, but thought it deserved a brief post:
A senior manager in the company arbitrarily pulls a date out of the air (normally the Friday just before an important golfing holiday) for when he needs a report. This means that a load of developers need to jump though hoops to write a system to produce the report, whilst having to continually deal with requirement changes and middle management customers that can’t actually make a decision about anything. When the system is delivered a week late, the senior manager is already playing golf and doesn’t care anymore, so all the developers are sacked.

More on TiddlyBlogger

February 17, 2009 by boycook

Just a quick note to point out some work that’s been done “White Hat Marketer”

Check out the details here:

http://whitehat-marketer.com/blog/tiddlyblogger-with-permalinks-and-updates/

It basically includes the capability to update posts (rather than just create new ones), and also create permalinks.

C# Win32 messaging with SendMessage and WM_COPYDATA

July 29, 2008 by boycook

I had a real pain recently where I wanted to control one windows app from another. I found some useful stuff on the net, but nothing that gave an end to end solution. So here’s what I came up with.

Firstly I’ll explain why this is useful. SendMessage is part of the Win32 API, and is used to send messages from one application to another. There are a set of predefined properties that the message can relate to, and these can be used to send messages to existing applications to perform all sorts of useful functions such as changing the font in notepad, or bringing a window to the fore. For more information of the wider use of the SendMessage function, have a look at:

http://www.autohotkey.com/docs/commands/PostMessage.htm

http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx

The main use that I’m interested in is passing a specific instruction (via a string) from one app that I’ve written, to another one that I’ve written. This way I can effectively remote control one app from another (particularly useful if you want your main application to open a pop-up, and you don’t want to worry about the pop-up’s performance affecting the main application). Let’s now have a quick look at the SendMessage function:

SendMessage(int hWnd, int Msg, int wParam, int lParam)

hWnd – This is the window instance id of the application you want to send a message to. This id is retrieved using the FindWindow function

Msg – This is the type of message you want to send

wParam – Message specific data you pass in

wParam – Message specific data you pass in

Also used is the FindWindow function. This is to get the relevant window id:

FindWindow(String lpClassName, String lpWindowName)

lpClassName -The name of the class you want

lpWindowName – The name of the window that you want

To send a message that is a string, you need to use the WM_DATACOPY message property. The hard part is that you cannot just send the string as a parameter across. You need to send a pointer to the memory address of the string. If you just want to send an integer as a message you can use the WM_USER message property and send it as a value without a problem.

Below now is a brief listing of my MessageHelper.cs class, for the whole class file see:

http://craigcook.co.uk/samples/MessageHelper.cs.txt

//////////////////// Code Begins ////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices;
using System.Diagnostics;

public class MessageHelper
{
[DllImport("User32.dll")]
private static extern int RegisterWindowMessage(string lpString);

[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern Int32 FindWindow(String lpClassName, String lpWindowName);

//For use with WM_COPYDATA and COPYDATASTRUCT
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, int Msg, int wParam, ref COPYDATASTRUCT lParam);

//For use with WM_COPYDATA and COPYDATASTRUCT
[DllImport("User32.dll", EntryPoint = "PostMessage")]
public static extern int PostMessage(int hWnd, int Msg, int wParam, ref COPYDATASTRUCT lParam);

[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);

[DllImport("User32.dll", EntryPoint = "PostMessage")]
public static extern int PostMessage(int hWnd, int Msg, int wParam, int lParam);

[DllImport("User32.dll", EntryPoint = "SetForegroundWindow")]
public static extern bool SetForegroundWindow(int hWnd);

public const int WM_USER = 0×400;
public const int WM_COPYDATA = 0×4A;

//Used for WM_COPYDATA for string messages
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
[MarshalAs(UnmanagedType.LPStr)]
public string lpData;
}

public bool bringAppToFront(int hWnd)
{
return SetForegroundWindow(hWnd);
}

public int sendWindowsStringMessage(int hWnd, int wParam, string msg)
{
int result = 0;

if (hWnd > 0)
{
byte[] sarr = System.Text.Encoding.Default.GetBytes(msg);
int len = sarr.Length;
COPYDATASTRUCT cds;
cds.dwData = (IntPtr)100;
cds.lpData = msg;
cds.cbData = len + 1;
result = SendMessage(hWnd, WM_COPYDATA, wParam, ref cds);
}

return result;
}

public int sendWindowsMessage(int hWnd, int Msg, int wParam, int lParam)
{
int result = 0;

if (hWnd > 0)
{
result = SendMessage(hWnd, Msg, wParam, lParam);
}

return result;
}

public int getWindowId(string className, string windowName)
{

return FindWindow(className, windowName);

}
}

//////////////////// Code Ends ////////////////////

So now you can call the code to send a message like so:

MessageHelper msg = new MessageHelper();
int result = 0;
//First param can be null
int hWnd = msg.getWindowId(null, “My App Name”);
result = msg.sendWindowsStringMessage(hWnd, 0, “Some_String_Message”);
//Or for an integer message
result = msg.sendWindowsMessage(hWnd, MessageHelper.WM_USER, 123, 456);

Now all you need to do on the app that you want to receive the message is override the following function in the form class (obviously you can change what the responses are, and you’ll need to create constants for the parameters):

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_USER:
MessageBox.Show(“Message recieved: ” + m.WParam + ” – ” + m.LParam);
break;
case WM_COPYDATA:
COPYDATASTRUCT mystr = new COPYDATASTRUCT();
Type mytype = mystr.GetType();
mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
this.doSomethingWithMessage(mystr.lpData);
break;
}

base.WndProc(ref m);
}

TiddlyBlogger updated

November 5, 2007 by boycook

I’ve recently updated my original TiddlyBlogger code to include JayFresh’s additions mentioned here (cheers for your work here Jon).

The added features are:

  • You can publish tags
  • You get a response to the XML-RPC Ajax call (i.e. you know if your post was successful
  • The ‘publish as blog’ option now only appears when you add the tag ‘blog’ to your tiddler.

Changes planned for the future are:

  • Being able to pull down blogs from WordPress (and editing them).
  • Support for more complex formatting (hyper links, bullet points etc)

Musings on facebook status’

November 2, 2007 by boycook

Over the last few days I’ve noticed something strange happening. I’ve started to think in terms of my facebook status. I’ll be at my desk and in my head I’ll say ‘Craig is…’ something or the other. Earlier on I was thinking ‘Craig is… going for a haircut’, when I got back I was thinking ‘Craig is… wondering why hairdressers never listen’. I think you get the point.

My point is that it’s become almost second nature to me to transpose what I’m doing and feeling into facebook terminology. I wonder has anyone else noticed this?

I wonder if it will affect us in any other ways? Will we find ourselves thinking differently as we need to cope with managing both out online (virtual?) and physical selves.

I’d love to hear peoples thoughts.

Media streaming with PS3 (DivX, Xvid)

October 30, 2007 by boycook

I’ve had a strange day today. I started off loving Sony, then I hated them, now I’m almost loving them again. I’ll explain:

I’m fed up with watching all of the torrents that I download on my PC in my study. I’ve got a 19′ widescreen monitor so it’s not terrible, but in my front room I have a 32′ TV and a projector, and I felt like it’s going to waste, especially as most of what I watch is downloaded.

So I set about to use the DLNA media streaming capabilities of my PS3 (this also works using an Xbox360):

  • I have a local wireless network onto which my PC’s, PS3, XBox360 etc are all attached. So I thought that this would be easy.
  • In your PS3 settings you need to ‘enable media server’ (or the like).
  • Then on you PC you go to Windows Media Player (11, or Media Center) select ‘library menu’ and then ‘media sharing’. From here you can set the permissions for your different devices.
  • If your device does not appear you’ll need to either change your firewall settings to let media player through, or you can disable it all together.
  • Make sure you add files to your library.

I was now loving Sony. If you restart your PS3 (or search for media server), your PC will now appear and you can browse to files. Ahh, this is where you get a problem. The PS3 only supports mpeg media format. Now I hated Sony. You can do what some sites suggest and re-encode all of your files, or you can just use some other software to stream.

This is where I discovered  TVersity. This works in a similar way in that you need to build your libraries etc, but the cool thing about this is that it will change the format of the file to one accepted by the client as it streams it, and you don’t need to go and re-encode all of your media. In other words you can now play all of your downloads (DivX, XVid avi’s) on your PS3. Cool eh. Now I’m kind of fond of Sony, but waiting for them to release more codecs for the PS3.

Link for 2007-10-21

October 21, 2007 by boycook

I’m not normally impressed by feats of extreme nerdness but this is pretty impressive. This guys plays tetris seriously quickly, and he then plays it with invisible bricks. Check it out:

http://youtube.com/watch?v=jwC544Z37qo

Musings on The Godfather

October 21, 2007 by boycook

I recently watched The Godfather (parts one and two) again and was again blown away by the story. The thing that particularly fascinated was watching the similarities and difference between father and son (Vito and Michael). I won’t talk for too long about this, just wanted to note a few observations.

Both characters have the same main focus: the family. To both father and son, the family is the most important thing in their lives, and the way that they protect and better the family is through the family business. So they both center their lives around making sure the family business thrives. They do anything to keep it going, keep it respected, and to get rid of the competition.
There are also some firm principles that they both have. A key thing is respect. They demand respect from others, but also give respect where respect is due.

The thing that I find more interesting though are the differences, and I think they come from the start of both characters.

We see in the first film that Michael originally didn’t want to be involved with the family business (especially not the illegal parts), but he was almost pushed into becoming involved. By a mixture of both his own principles (love and respect for his father/family) and circumstance (the assassination attempt on his father) he found himself in the situation where he does get involved. In order to protect his father and family he murders two people. This is a brilliant scene because there is no music, just the sound of a train going past. As the train gets nearer you can feel the tension building. He’s thinking that once he does this his life will change forever. He’ll be a part of the family’s illegal activities.

In the second film we see the beginnings of Vito. As a young boy (I think he was 9 or 10) his father is murdered. Then on the way to the funeral his older brother is murdered. His mother begging for her child’s life is then murdered in front of him. Vito runs for his life and flees to the US. Vito turns to crime (I wouldn’t say that he’s forced) to help his family and friends. You get the feeling that he feels sorry for the people that are lesser off, and that get taken advantage of by those around. All he asks for is respect (and a favour at a later date).

Anyway my point is this: There is a scene in the second film that I think sums up what I mean and I’ll copy it here:

MICHAEL
…Tell me, when Pop had troubles…
did he ever think, even to himself,
that he had gone the wrong way;
that maybe by trying to be strong
and trying to protect his family,
that he could… that he could…
lose it instead?

MAMA
(Sicilian)
You talk about the baby. She can
have another baby.

MICHAEL
(Sicilian)
No, I meant lose his family.

MAMA
(as best she ever
understood it)
Your family? How can you ever lose
your family?

MICHAEL
(almost to himself)
But times are different…

Michael is now realising that his actions to make the family the most successful/powerful have actually made the rest of his family fear and dislike him. Look at his position at the end of the film – both his parents are dead (natural causes), his older brother is dead (assassinated by enemy), lots of family friends have been killed (some by him), he had his sisters husband killed and now she hates him, he had his own brother killed, and finally his wife aborted their child and left him.

In trying to protect his family, and a lot of that is by him doing the dirty work so that they don’t have to, he has ended up pushing them away.

Tidying up code

October 21, 2007 by boycook

I’ve gone through some of my sample files and tided up the code a bit:

http://www.craigcook.co.uk/samples/

I’ve changed the TiddlyWiki’s to have all of the code in one file (keeping with the ToddlyWiki sentiment). The script files are still there, and I’ll still keep adding them.

Goodbye Carson

October 21, 2007 by boycook

I posted this in my old blog, but I thought I’d repost it here:

When I first heard that Dr. Beckett was going to be killed off in season 3 of Atlantis I was pleased. To be honest he always annoyed me, I thought that the creators were just trying to keep to a similar format to SG-1, where a doctor is a main character. I must also say that Dr Frasier in SG-1 had never been a favourite character of mine either.

The strange thing is that during that episode ‘Sunday’ I was actually starting to feel sorry for him. He was just trying to have a day off where he could relax and connect with some of his colleagues (friends), but his attempts were either brushed off or too late. I then realised that the previous few episodes had started to make me like him. It suddenly hit me ‘this is it’ he’s going to die in this episode, and I did genuinely feel sorry for him. It wasn’t exactly the most dignified of deaths, an exploding tumour, but at least it was noble. Carson was self sacrificing to the end, and will be remembered by fans of the show.

We can learn from this not to take for granted those that we have around us on a day-to-day basis. Some people may irritate or annoy us at times, but at the end of the day the world is a lesser place without them.