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!

Localization using WPF and C#

For anyone who is interested I have posted a tutorial on building a localizable application using C# and WPF here for anyone who is interested. I will hopefully post a copy here in time but for the moment I see no need to duplicate the content.

If you have any comments, suggestions or improvements please let me know!

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.

1
2
IPHostEntry localIPAddresses = Dns.GetHostEntry(Dns.GetHostName());
string localIP = (from ip in localIPAddresses.AddressList where (ip.AddressFamily == AddressFamily.InterNetwork) select ip).First().ToString();

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:

1
#include <intrin.h>

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.

1
2
3
4
5
6
7
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
extern "C" __declspec(dllexport) CPUInfo cpuID(int infoType)
{
    CPUInfo i;
    int results[4] = { 0, 0, 0, 0 };
    __try
    {
        __cpuid(results, infoType);
    }
    __except (EXCEPTION_EXECUTE_HANDLER) {}

    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:

1
extern "C" __declspec(dllexport) CPUInfo cpuID(int infoType);

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:

1
2
3
4
5
6
7
8
[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:

1
2
3
4
5
6
7
/// <summary>
/// This pinvoke method will return the result from a __cpuid call, if supported.
/// </summary>
/// <param name="infoType">A code that indicates what information this instruction retrieves.</param>
/// <returns>A CPUInfo structure giving the result from the query, or an empty structure if not supported.</returns>
[DllImport("HardwareInfo.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern CPUInfo _cpuid(uint infoType);

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

1
2
CPUInfo example = cpuID(0x00000000);
uint maxSupportedStandardLevels = (uint)(example.EAX & 0xffff);

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

Notes:

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.

CSIT Interface Designs

Hi guys!

It has been a busy week so I have not had much time to blog about my work and activities. Due to developments it seems the CoalFields funding for CCC will not be available in July as hoped – probably not until September or October. That is a pity but it will not stop us moving forward.

But! That is not why I am blogging today – I am here today to discuss some work I have been doing on the CSIT main interface.

After much deliberations between myself and Ashley Vaughan we argued the idea to the following interface style.

CSIT Main Window Design v2
CSIT Main Window Design v2

The design is simple, clean and should be easy to modify in the future. As you can see there are tabs dividing hardware and software (and there may be others there too). Next on the left of each tab there are the categories found under expanders. These will be made into accordion-style items eventually though I think it is more important to get the program working first. Finally on the right are the tabs containing the information from the selected category.

It was quite difficult deciding on one design since there were so many to choose from.

As always, any comments or suggestions relating to the design please post or contact me.

HTML5 Audio Experiments and the Future of the Internet

I have just finished reading the “Experiments with audio” blog post collection by David Humphrey. I must say I am pretty impressed by what has been achieved in such a short time.

I am sure that there are many people out there who would be interested in accessing the raw data APIs for HTML5 audio to directly modify and generate graphics for the music, up until now something that could only be done with technologies such as Flash.

This may well be another step forward for the open web and will certainly expand the usefulness of the HTML5 audio and video tags. I am looking forward to seeing how this develops. This should also hold benefits for other people, even those who are not interested directly in the technology since this and other such APIs should push forward the performance improvements of JavaScript on the internet since the graphic and processing engines are entirely written in JavaScript.

Good work guys!