Sciguyryan's Blog

Thoughts on Localization with WPF

by on Jun.13, 2010, under General, Personal

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.

Comments Off more...

Stupid Mistakes

by on Jun.11, 2010, under Personal

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!

Comments Off more...

Firefox, YouTube and WebM – The Experiment

by on Jun.10, 2010, under General, Personal

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!
Comments Off more...

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

by on Jun.09, 2010, under Code Snippet

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.

Comments Off more...

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

by on Jun.06, 2010, under Personal

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.

Comments Off more...

CSIT Interface Designs

by on Jun.06, 2010, under News, Projects

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.

Comments Off more...

HTML5 Audio Experiments and the Future of the Internet

by on Jun.01, 2010, under General

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!

Comments Off more...

Microsoft’s and a Lack of Documentation

by on May.31, 2010, under General

Today I have been working on the operating system identification engine for CSIT. However. I have been quite frustrated by Mirosoft’s lack of documentation for some items. I have been using the GetProductInfo function call via pinvoke from C#. After digging around in the WinNT.h header file that came with Visual Studio I found the definitions for the product versions that can be returned.

However, to my disappointment some of them are complete undocumented by Microsoft! Items such as these:

#define PRODUCT_SB_SOLUTION_SERVER_EM               0×00000036
#define PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM          0×00000037

… have absolutely no definition, anywhere. Without a definition I cannot use these and so they are totally useless. I ask you Microsoft, why do you include definitions but fail to provide an exploitation of what they are? They must mean something but what that is, I have no idea until Microsoft choose to update their documentation.

Hopefully someone from Microsoft with the power to change this will read this post and do something about it. But if anyone has any idea what these keys mean and have a reference somewhere – please let me know!

Comments Off more...

CSIT Update

by on May.29, 2010, under News, Projects

Hi everyone!

I am pleased to report that I have finally made some decent progress with CSIT. I now have the pinvoke links completed and functioning, I can also get access to the features that a CPU supports as well as information about the caches and other information about the CPU – yay!

Below is a screenshot showing some of the information that I have succeeded in extracting from the deep code calls.

CSIT Information Screen v0.1

Looks simple doesn’t it? Well. You probably wouldn’t believe it but the framework code written to reach this point has just passed four thousand lines!

If anyone has any comments or suggestions about other features that should be included or improved then please let me know! However please note that this is nowhere near completed and these are just testing features. I have lots more planned yet!

Comments Off more...

First Code Snippet – Simple Hertz and Bytes Converters (C#)

by on May.28, 2010, under Code Snippet

Hi everyone!

These are my first code snippets. These were written as part of my CSIT project and are used to convert sizes and frequencies easily from one type to another. First lets look at the byte conversion function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public enum ByteUnits : int
{
    B,
    kB,
    MB,
    GB,
    TB,
    PB
}

public static string Bytes2Size(double value, ByteUnits fromType = ByteUnits.B)
{
    // If the bytes are 0 then we can logically go no further.
    if (value == 0)
    {
        return "0 B";
    }

    // First we need to convert the value back into the smallest unit.
    double from = (value * Math.Pow(1024, (double)fromType));

    // This will give us the index of the best size to use.
    double exponent = Math.Floor(Math.Log(from) / Math.Log(1024));

    // Return the processed value.
    return (from / Math.Pow(1024, exponent)).ToString("n2") + " " + Enum.GetName(typeof(ByteUnits), (int)exponent);
 }

As you can see the code above is relatively simple. Here is a a basic description of the process:

  1. lines 9 – 11 do a check to ensure that no 0′s fall into the function. Since, if they did, it would break the result.
  2. Line 15 converts the original value into the most basic unit that this type supports. In the case of the example above it converts the value back into bytes.
  3. Line 18 gathers the exponent. This will represent the index of the enumeration that the value should be converted into (basically anyway).
  4. Line 21 converts the value and then adds the symbol thanks to some .NET magic, then returns the result.

As you can see, these are pretty simple. They just contain the sets of units to be used in the conversions. One of the best features of this approach is that you simply need to add the symbol for the next unit to be able to translate to that higher unit. Simple no? I also promised you a version of the above function that converts the hertz unit – so here it is.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public enum HertzUnits : int
{
    Hz,
    KHz,
    MHz,
    GHz,
    THz,
    PHz
}

public static string Hertz2Frequency(double value, HertzUnits fromType = HertzUnits.Hz)
{
    // If the bytes are 0 then we can logically go no further.
    if (value == 0)
    {
        return "0 Hz";
    }

    // Get the original value.
    double from = (value * Math.Pow(1000, (double)fromType));

    // This will give us the index of the best size to use.
    double exponent = Math.Floor(Math.Log(from) / Math.Log(1000));

    // Return the processed value.
    return (from / Math.Pow(1000, exponent)).ToString("n2") + " " + Enum.GetName(typeof(HertzUnits), (int)exponent);
}

I hope you enjoyed this snippet. If you have anything you wish to say or suggest feel free to comment.

Comments Off more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...