New PC!

Hi everyone!

Well. I have finally ordered my new PC and it is going to be a monster. It will have 12GB of 1600 MHz memory, a solid state hard drive and liquid cooling as an i7 processor. I can’t wait for it to come back, it should be here sometime next week.

I will post about my experience with the new system when I get it.

Busy, Busy!

Hi everyone!

Sorry for the lack of blog posts recently. I have been quite busy with CCC related work. Now that we’ve sent off the 90k bid to the CoalFields Regeneration Trust and the 45k bid to the Rhonda Trust I have a little more free time. I will be getting a new computer in short order and then I should be able to continue work on CSIT (and hopefully provide some updates for you guys!).

Hopefully I will talk more soon!

CSIT and Network Information

Hi guys!

Network information is a complex subject at the best of times and simplifying it for the average user is no simple feat. Even harder it seems is actually writing code to get this information programatically! I was quite disappointed to find that there was no simple way to get an IP address via code – mainly since Windows does not actually know it until a request is made. I eventually made a work around and used a web script to scrape the information. It saved a lot of time and effort in the end.

Getting the internal IP address was also quite interesting. It involved using some built-in .NET code. The only issue is that there were nearly always IPv6 addresses returned first. Since these are not well known (yet) I decided to list only the IPv4 address instead. The code I came up with is listed below – hopefully it will help someone else.

[cc lang=”c#]IPHostEntry localIPAddresses = Dns.GetHostEntry(Dns.GetHostName());
string localIP = (from ip in localIPAddresses.AddressList where (ip.AddressFamily == AddressFamily.InterNetwork) select ip).First().ToString();[/cc]

As you can see I also use LINQ there instead of a foreach loop since I find it much more readable. I am nearly finished with the main basic info page now so pretty soon I will have some new screen shots to demonstrate the new design of CSIT!

Thoughts on Localization with WPF

Hi everyone!

I just thought I would stop by and share some thoughts with you on localization with WPF. I have spent the last few hours working on making CSIT localization before I add to much content to make it worth while. This is the first time I have ever made the effort to make an application localizable and I must say that it was not as painful as I thought it would be.

Eventually I decided to use a simple XML file and bound elements to it using data binding and XPath. Some things could not be bound to however and I had to implement a class that would read strings from the file and load them so they can be used later in the processing functions.

So far however it seems to be working just fine. And as proof here is a screenshot of the current CSIT interface that uses the new localization system.

The current CSIT Interface (v3)

Hopefully I will be posting more on this shortly. Once I am sure that the code works as intended I will try to release the code for others to use.

Stupid Mistakes

I spent a good few hours yesterday trying to figure out why my code to extract the Windows key from the registry was not working. The key was there but the code would not read it! It was infuriating.

After taking a little time to sit back and think about the problem – it dawned upon me. I am using a 64-bit operating system. This means that although the key appeared to be present in the location I was checking, it may indeed have been under the WOW64 part. After digging there it was.

With only a few modifications to my code, it now works successfully. I am quite pleased that Microsoft added a method to the register editing features in .NET framework 4 and for those who are interested I used the OpenBaseKey method of the RegistryKey class with the RegistryView attribute set depending on if the operating system is 64-bit or not.

The code now works perfectly. Let that be a lesson to you – focusing on answers to simple problems gets you nowhere fast!

Firefox, YouTube and WebM – The Experiment

Hi everyone

I have just spent a little while playing with the new WebM and HTML5 experimental support in Mozilla Firefox and I mus say. I am quite impressed. The 760p video samples I have seen are truly quite impressive. I would suggest that anyone capable should get their hands on a browser with experimental support and give it a shot themselves.

But for those of you who are not so daring – here are a few screen shot of what a video looks like in 720p with the new experimental features. For those who are a little more daring, see the information at the bottom of this page about where you can find the experimental Firefox builds.

WebM Sample 1 (720p)
WebM Sample 2 (720p)
WebM Sample 3 (720p)

Firefox Experimental Builds

  1. First you will need to go and get yourself a Firefox nightly build, or a nightly of your favourite browser. If you use Windows then you can get a build here. For Mac you can get a build here and for Linux you can get it from here.
  2. Install the nightly build. Note that if you are already using Firefox you may wish to read this before you install it!
  3. Load the the video here and try out the different resolution settings and enjoy!

Calling the __cpuid MSVC function via C# a DLL Pinvoke (C++, C#)

Here is the latest piece of code I wish to share with everyone since I run into this myself, I am sure others will be interested also.

The C++ Part

Firstly you will need to create a new DLL project in Visual Studio. You will also need to add this line into the cpp file for your project:

[cc lang=”c++”]#include [/cc]

This will allow you to access the intrinsic __cpuid call.

Next, I use a custom structure to hold the data returned by the function call. I do this mainly for readability since it helps when referencing. The code for the structure is as follows and should be added to the header file.

[cc lang=”c++”]struct CPUInfo
int EAX;
int EBX;
int ECX;
int EDX;

Simple enough eh? Good. Now we need to construct a function call that will wrap the results from a __cpuid call into the structure above. Again, this is quite simple:

[cc lang=”c++”]extern “C” __declspec(dllexport) CPUInfo cpuID(int infoType)
CPUInfo i;
int results[4] = { 0, 0, 0, 0 };
__cpuid(results, infoType);

i.EAX = results[0];
i.EBX = results[1];
i.ECX = results[2];
i.EDX = results[3];

return i;

Finally you will need the following function definition for the header file:

[cc lang=”c++”]extern “C” __declspec(dllexport) CPUInfo cpuID(int infoType);[/cc]

As you can see. The above function also checks for any exceptions – it needs this as some older CPUs do not support the cpuid call. In these cases it will simply return a CPUInfo structure filled with 0’s so that the code doesn’t break anything.

Now. You will need to compile the DLL and then you can use it in your C# project using the following method.

The C# Part

First. Create an analogue of the C++ CPUInfo class in C#. This is really simple to do and the following is what is needed, for those who do not wish to try themselves:

[cc lang=”c#”][StructLayout(LayoutKind.Sequential)]
struct CPUInfo
public int EAX;
public int EBX;
public int ECX;
public int EDX;

Finally you will need the pinvoke definition. Depending on the name of the DLL (I called mine HardwareInfo.dll) the following code will be slightly different:

[cc lang=”c#”]///

/// This pinvoke method will return the result from a __cpuid call, if supported.

/// A code that indicates what information this instruction retrieves. /// A CPUInfo structure giving the result from the query, or an empty structure if not supported.
[DllImport(“HardwareInfo.dll”, CallingConvention = CallingConvention.Cdecl)]
public static extern CPUInfo _cpuid(uint infoType);[/cc]

Hopefully that wasn’t too bad. Here is an example of how you would use the above code:

[cc lang=”c#”]CPUInfo example = cpuID(0x00000000);
uint maxSupportedStandardLevels = (uint)(example.EAX & 0xffff);[/cc]

The above code will tell you the maximum supported level of call that is supported on the current processor.


Just remember that you will need to add a reference to the System.Runtime.InteropServices namespace if you are going to use this code.

As always, comments, improvements and suggestions are welcome.

Apple’s HTML5 Demos – Safari Only. No Other Browsers Welcome?

After reading a very interesting blog post by Rob Sayre from Mozilla I was pretty irritated by Apple’s irresponsibility.

HTML5 is a cross-browser standard but Apple are using it as a marketing tool to try and peg their own browser by making it seem like other browsers are not compatible – when in actuality they are if Apple made an effort to include the code for other browsers and not using cheap browser detection scripts.

This is a move I would expect from Microsoft rather than Apple and I find it quite disturbing that they have done something like this.

Hopefully they will correct this issue since it will do their image no good to keep things the way they are.