Monday, September 6, 2010

Using NKDbgPrintfW in the Compact Framework


In case you wanted to use RETAILMSG or NKDbgPrintfW in your C# code and was struck dumb when you saw that no Dll was specified for the function on the MSDN page have no fear.
As you may have guessed, you need to use Coredll.dll for the declaration. I tried and confirmed it.

[DllImport("Coredll.dll")]
public static extern void NKDbgPrintfW(string str);

Format the string before sending it to the native function to avoid the multiple variable stuff...

Tuesday, July 6, 2010

Make your OSDesign more readable

There are some unknown hidden tags to the sources file that can make the navigation through your OSDesign much easier and convenient.
One of these excellent tags is FILE_VIEW_INCLUDES_FOLDER. This excellent tag makes files such as txt,jpg, etc.. accessible through the IDE. Pretty comfortable!

Sunday, June 13, 2010

IOCTL_HAL_INITREGISTRY and its place in the boot order

I'll start by saying that this is intended for OEM platform developers.

When you develop an OSDesign it usually supports several hardware configurations. One of the first questions that arises is where in the boot process can we decide what is the configuration we are running on and which drivers should we enable. For this purpose Microsoft introduces IOCTL_HAL_INITREGISTRY.

This OAL IOCTL is called in the boot phase. The description by Microsoft is:
It is called before other applications are started, so the OAL can modify registry settings used by all applications.
This is where this post comes in. From what I have experienced, using Hive Based registry, the registry that is available in this function is the Hive Boot section. Any change that is done to the registry will be merged (override) to the boot phase of the device manager.

The delicate points to pay attention to are:
  1. Changes that have been saved before the last restart are not reflected in the current state of the registry.
  2. After this function finishes the device manager is loaded. This means that boot phase one relies on the updated registry. So, if you add driver entries in this functions you may encounter weird problems in the loading order of drivers (suddenly drivers will load in boot phase one when they were not supposed to be avialble yet).
To solve number 2 I use the following solution:
Say I have two hardware implementations for a USB controller (revision 1.2 of the HW has a differnet controller than revision 1.1). This means I need two different code paths to initialize the hardware. Admittedly, there are many ways to implement this, but what I do is put two different drivers in the source code and add two different entries in the registry. When the IOCTL_HAL_INITREGISTRY is called I update the flags entry of the corresponding drivers based on the revision of the board.

Additional reading:
How to set up an OAL IOCTL

Tuesday, March 9, 2010

All I wanted to do was move to GIT...

I received a simple assignment: move our svn repository to git.
You can skip to the end and read the steps to take or read the boring story that led to this blog post.

I thought it shouldn't be hard since our repository is local and you have git-svn. Well it's not that easy as well.
I must admit, I am lazy. I don't want to do it in batch mode and I don't want to be the master of git and svn to accomplish this. At the end I was forced to work in batch mode most of the time.

So I started by doing a simple google search and found the following blog:
Cleanly migrate your svn repository
Sounds promising!
My repository is located at C:\SVNRep so I typed:
git svn c:\svnrep --no-metadata
Wrong!
Once I issued the: "git fetch" I was warned that it could not find the svn repository.
Back to searching. Now I found this answer on StackOverFlow. I understood I am an idiot. No surprise there...
I tried to issue the following:
git svn file://c:/svnrep --no-metadata
The process started and I was happy.  BUT, I received another error: similar to "Permission denied: error line 2723" with a tmp folder that was not in my svn repository. Google dug an answer quite fast with this message:
Porting svn with an error
I thought I was done, but apparently I am not that talented when it comes to svn.

I downloaded the svn version I created the repository with (1.6.5) and ran the svnserve command only to find that git did not find the path I specified (svn://localhost/relative/svnrep/). I then downloaded VisualSVN, copied my repository to the repositories directory and created a user with the same name as the Windows user. I was now able to access my repository through the web with the user I created. So.... once again I hit:
git init http://shay-vm-git/svn/SVNRep/ --no-metadata
This time it worked!!! The process takes along time to finish.

To summarize:
System settings -
  • Windows XP SP3
  • VisualSVN with SVN 1.6.5
  • Git-1.6.5.1-preview20091022.exe
Objective -
Steps to take-
  • Read  Cleanly migrate your svn repository
  • Read Porting svn with an error
  • Install VisualSVN that corresponds to the SVN version of your svn repository
  • Create a user in VisualSVN with the same name of the user you are logged-on with in Windows
  • Copy your repository to the Repositories folder of VisualSVN
  • Right click the repository folder in VisualSVN and choose Browse
  • Copy the URL of your repository from the web page that opened and use it in the "git init svn_address --no-metadata" command
  • Wait a long time for the fetch to finish
Hope this helped someone.

Thursday, February 25, 2010

The new Windows CE Internet Explorer missing icon

The newly released Internet Explorer for Windows CE comes without a shortcut on the desktop. Annoying and funny that Microsoft missed that (and did not fix it via a QFE).

Not only they did not place a shortcut, but they also did not set an icon for the new application. This means that placing a regular shortcut will look odd since the shortcut takes the icon from the executable it points to.

I am adding a link to a subproject that adds an application with the IE icon that launches the new IE. The subproject also places a shortcut on the desktop.

The subproject is not built in case the component for the new IE is not chosen.




No warranty is given in any way. The code is supplied as is.

Tuesday, February 23, 2010

Platform Builder 6 and Windows 7 64 bit

A fresh install of VS2005 and Platform Builder 6 on a Windows 7 64 bit does not work.
To save you some trouble of searching the web go straight to the following post and read it: link


Read MichaelH's solution at the end. It works.

QFE mess?

With the release of Windows CE R3 the CE Updates tool ceased to function. Add the fact that the instructions on Microsoft's website were confusing at first you get a mess when it comes to updates.
To check what updates you have installed, you can open the folder %WINCEDrive%\Wince600\updates


By the way, the easiest way to get past the confusion with R3 is to just install the yearly update of 2009 after you install R3 and that's that.

Saturday, January 23, 2010

Silverlight Error codes in String format

I recently had to debug a simple Silverlight application and found myself looking for the error code one Silverlghit function gave me. Soooo I ended up creating this function that can help you when you debug your application. Nothing fancy, it will just save you time doing the same:

TCHAR*    GetSilverLightErrorString(
HRESULT retcode)
{
    static TCHAR    pszUnknownMessage[50];
    static    TCHAR    pszErrorStrings[][50] =
    {
        {TEXT("XR_E_ABSTRACT_BASE_CLASS")},//0
        {TEXT("XR_E_COLLECTION_DUPLICATE_NAME")},//1
        {TEXT("XR_E_COLLECTION_ELEMENT_ALREADY_ASSOCIATED")},//2
        {TEXT("XR_E_DUPLICATE_REGISTRATION")},//3
        {TEXT("XR_E_ELEMENT_NOT_CREATED")},//4
        {TEXT("XR_E_ELEMENT_NOT_FOUND")},//5
        {TEXT("XR_E_INVALID_OBJECT")},//6
        {TEXT("XR_E_INVALID_PROPERTY")},//7
        {TEXT("XR_E_INVALID_ROOT_FOR_CREATING_HOST")},//8
        {TEXT("XR_E_INVALID_STATE")},//9
        {TEXT("XR_E_INVALID_THREAD_ACCESS")},//10
        {TEXT("XR_E_NOT_INITIALIZED")},//11
        {TEXT("XR_E_PARSER_ATTRIBUTE_OUT_OF_RANGE")},//12
        {TEXT("XR_E_PARSER_ATTRIBUTE_READONLY")},//13
        {TEXT("XR_E_PARSER_FAILED_RESOURCE_FIND")},//14
        {TEXT("XR_E_PARSER_INVALID_ATTRIBUTE")},//15
        {TEXT("XR_E_PARSER_INVALID_ATTRIBUTE_VALUE")},//16
        {TEXT("XR_E_PARSER_INVALID_CONTENT")},//17
        {TEXT("XR_E_PARSER_INVALID_PROPERTY")},//18
        {TEXT("XR_E_PARSER_MISSING_DEFAULT_NAMESPACE")},//19
        {TEXT("XR_E_PARSER_MULTIPLE_PROPERTY_ELEMENT_VALUES")},//20
        {TEXT("XR_E_PARSER_RESOURCE_KEY_AND_NAME_SET")},//21
        {TEXT("XR_E_PARSER_TEXT_CONTENT_UNSUPPORTED")},//22
        {TEXT("XR_E_PARSER_UNKNOWN_ATTRIBUTE")},//23
        {TEXT("XR_E_PARSER_UNKNOWN_ELEMENT")},//24
        {TEXT("XR_E_PARSER_UNKNOWN_NAMESPACE")},//25
        {TEXT("XR_E_STORYBOARD_BEGIN_ANIMATION_COMPOSITION")},//26
        {TEXT("XR_E_STORYBOARD_BEGIN_INCOMPATIBLE_TYPE")},//27
        {TEXT("XR_E_STORYBOARD_BEGIN_INVALID_KEYTIME")},//28
        {TEXT("XR_E_STORYBOARD_BEGIN_INVALID_PROPERTY")},//29
        {TEXT("XR_E_STORYBOARD_BEGIN_INVALID_TARGET")},//30
        {TEXT("XR_E_STORYBOARD_BEGIN_NO_TARGET")},//31
        {TEXT("XR_E_STORYBOARD_MODIFY_ACTIVE_ANIMATION")},//32
        {TEXT("XR_E_STORYBOARD_MUST_BE_ROOT ")},//33
        {TEXT("XR_E_STORYBOARD_SKIPTOFILL_NO_DURATION")}//34
    };

    switch(retcode)
    {
        case XR_E_ABSTRACT_BASE_CLASS:
            return pszErrorStrings[0];
        case XR_E_COLLECTION_DUPLICATE_NAME:
            return pszErrorStrings[1];
        case XR_E_COLLECTION_ELEMENT_ALREADY_ASSOCIATED:
            return pszErrorStrings[2];
        case XR_E_DUPLICATE_REGISTRATION:
            return pszErrorStrings[3];
        case XR_E_ELEMENT_NOT_CREATED:
            return pszErrorStrings[4];
        case XR_E_ELEMENT_NOT_FOUND:
            return pszErrorStrings[5];
        case XR_E_INVALID_OBJECT:
            return pszErrorStrings[6];
        case XR_E_INVALID_PROPERTY:
            return pszErrorStrings[7];
        case XR_E_INVALID_ROOT_FOR_CREATING_HOST:
            return pszErrorStrings[8];
        case XR_E_INVALID_STATE:
            return pszErrorStrings[9];
        case XR_E_INVALID_THREAD_ACCESS:
            return pszErrorStrings[10];
        case XR_E_NOT_INITIALIZED:
            return pszErrorStrings[11];
        case XR_E_PARSER_ATTRIBUTE_OUT_OF_RANGE:
            return pszErrorStrings[12];
        case XR_E_PARSER_ATTRIBUTE_READONLY:
            return pszErrorStrings[13];
        case XR_E_PARSER_FAILED_RESOURCE_FIND:
            return pszErrorStrings[14];
        case XR_E_PARSER_INVALID_ATTRIBUTE:
            return pszErrorStrings[15];
        case XR_E_PARSER_INVALID_ATTRIBUTE_VALUE:
            return pszErrorStrings[16];
        case XR_E_PARSER_INVALID_CONTENT:
            return pszErrorStrings[17];
        case XR_E_PARSER_INVALID_PROPERTY:
            return pszErrorStrings[18];
        case XR_E_PARSER_MISSING_DEFAULT_NAMESPACE:
            return pszErrorStrings[19];
        case XR_E_PARSER_MULTIPLE_PROPERTY_ELEMENT_VALUES:
            return pszErrorStrings[20];
        case XR_E_PARSER_RESOURCE_KEY_AND_NAME_SET:
            return pszErrorStrings[21];
        case XR_E_PARSER_TEXT_CONTENT_UNSUPPORTED:
            return pszErrorStrings[22];
        case XR_E_PARSER_UNKNOWN_ATTRIBUTE:
            return pszErrorStrings[23];
        case XR_E_PARSER_UNKNOWN_ELEMENT:
            return pszErrorStrings[24];
        case XR_E_PARSER_UNKNOWN_NAMESPACE:
            return pszErrorStrings[25];
        case XR_E_STORYBOARD_BEGIN_ANIMATION_COMPOSITION:
            return pszErrorStrings[26];
        case XR_E_STORYBOARD_BEGIN_INCOMPATIBLE_TYPE:
            return pszErrorStrings[27];
        case XR_E_STORYBOARD_BEGIN_INVALID_KEYTIME:
            return pszErrorStrings[28];
        case XR_E_STORYBOARD_BEGIN_INVALID_PROPERTY:
            return pszErrorStrings[29];
        case XR_E_STORYBOARD_BEGIN_INVALID_TARGET:
            return pszErrorStrings[30];
        case XR_E_STORYBOARD_BEGIN_NO_TARGET:
            return pszErrorStrings[31];
        case XR_E_STORYBOARD_MODIFY_ACTIVE_ANIMATION:
            return pszErrorStrings[32];
        case XR_E_STORYBOARD_MUST_BE_ROOT:
            return pszErrorStrings[33];
        case XR_E_STORYBOARD_SKIPTOFILL_NO_DURATION:
            return pszErrorStrings[34];
        default:
            _stprintf(pszUnknownMessage,TEXT("UNKNOWN_ERROR (0x%x)"), retcode);
            return pszUnknownMessage;
    }
}



This code is provided as is without ANY guarantees and might be mssing a few error codes.