January 2009 Entries

Windows CE: Priority Inversion and How I missed it
I have been working on a problem for a couple of weeks now. I even wrote about it in Windows CE: Finding an Out of Control Thread where I declared that I had found the thread that had the problem. It turns out that I was wrong, and I am willing to admit it. In Windows CE: Finding an Out of Control Thread I showed how I found the thread that was using 100% of the CPU time by finding the thread priority of the thread. I didn’t discuss it, but I did consider priority inversion and ruled that out. It ......

Posted On Saturday, January 31, 2009 9:18 PM | Comments (5)

Platform Builder: Cannot open include file: 'windows.h': No such file or directory
The following is unique to Platform Builder, and applies to any version. The problem is that when building a driver, BSP or sub-project, the compiler fails with the error message “Cannot open include file: 'windows.h': No such file or directory.” There are probably many ways to cause this error. Many of these are simple user error, like accidently deleting or moving windows.h. But let’s focus on the most likely problems that can cause this. 1. The most common cause that I have run into is that the ......

Posted On Friday, January 23, 2009 12:23 PM | Comments (0)

Books on my Shelf: Programming Windows Embedded CE 6.0
Programming Windows® Embedded CE 6.0 Developer Reference, Fourth Edition by Douglas Boling is a must read for anyone writing programs for Windows Embedded CE 6.0. This book is a must have because the author has a more than passing knowledge of the Windows CE architecture, and he does a very good job of explaining the details that one must know when writing Windows CE applications. While this book is primarily C/C++, the operating system information is valid for other languages as well. Anyone writing ......

Posted On Thursday, January 22, 2009 10:19 PM

Windows CE: Finding an Out of Control Thread
Last week I was working on a system would stop responding to the user after many hours of running. All we knew was that the CPU was still running software, and we only knew that because RAM was still being accessed. The other thing we knew was that the customer was not happy and we needed to learn more and fast. To make it more interesting, the problem was occurring on systems that we could not use traditional tools to work on. These systems were not sitting in a cozy office, heck we didn’t even ......

Posted On Wednesday, January 21, 2009 10:54 PM | Comments (21)

Windows CE: Threads
All code executes within a thread in Windows CE. A thread contains a stack and a program counter among other things. A thread runs at a priority level from 0 to 255, with 0 being the highest priority. Higher priority threads run before lower priority threads and can therefore block lower priority threads from running. The priority level of a thread can be changed. When a thread is scheduled to run, it will run for a period of time known as quantum or until the thread gives up its quantum by blocking. ......

Posted On Wednesday, January 21, 2009 9:07 PM | Comments (4)

Windows CE: Runtime OS Version
GetVersionEx() is a method for retrieving the Windows CE Version at runtime. The following function, OutputWindowsCEVersion(), demonstrates how to call GetVersionEx() and output the version information to the debug port. void OutputWindowsCEVersion() { OSVERSIONINFO Version; Version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (GetVersionEx(&Version)) { RETAILMSG(1, (TEXT("Windows CE %d.%d build %d\n"), Version.dwMajorVersion, Version.dwMinorVersion, Version.dwBuildNumber )); RETAILMSG( 1, ......

Posted On Saturday, January 17, 2009 8:24 PM | Comments (0)

Windows CE: Compile Time OS Version
Every time Microsoft releases a new version of Windows CE, there are changes to the available APIs. Most of the time there are additions of new APIs, but sometimes an API becomes obsolete and rarely an API changes signatures. If you are like me, you probably want to maintain as little source code as possible. That means that the code needs to compile under the different versions while taking advantage of new features. Bldver.h provides a way to check for the Windows CE version at compile time. Bldver.h ......

Posted On Friday, January 16, 2009 11:06 PM | Comments (2)

Windows CE: Interrupt Service Thread Example
In Windows CE: Interrupt Service Thread I discussed the steps required by an Interrupt Service Thread (IST.) Refer to that post for an explanation of the following code. static DWORD WINAPI DSInterruptThread(LPVOID p) { DWORD RetVal = 0; HANDLE hEvent; DWORD SysintrValue; DWORD IRQ = MYDRIVER_IRQ; // Create an Event hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // Register with the Kernel KernelIoControl(IOCTL_HAL_R... &IRQ, sizeof(DWORD), &SysintrValue, sizeof(DWORD), NULL) ......

Posted On Friday, January 16, 2009 10:43 PM | Comments (9)

Windows CE: Interrupt Service Thread
An Interrupt Service Thread (IST) is the way that drivers in Windows CE service an interrupt. Typically, a driver will contain a thread function that handles the interrupt, and does nothing else. A typical IST will do the following: 1. Create an Event 2. Register with the kernel 3. Set the thread priority 4. Wait for the event to be signaled 5. Service the hardware 6. Tell the kernel that the interrupt has been serviced 7. Repeat steps 3, 4 and 5 There are certainly variations in how ISTs are written ......

Posted On Thursday, January 15, 2009 8:37 PM | Comments (12)

Platform Builder: How to Determine the Baud Rate of the Serial Debug Port
Every once in a while, someone finds my blog by searching for how to determine the baud rate of the serial debug port. So I thought that I would look into how to answer that for them. First, try 38400, 8 bit, no parity, 1 stop bit and no handshaking. This is a common setting for the serial debug port. Second, read the documentation for your board if you bought it in a system from an OEM. Last, look in the code. If you need to do this, then you must be the OEM and using a BSP from either Microsoft ......

Posted On Monday, January 12, 2009 11:08 PM | Comments (0)

Windows CE 6.0: Example UIProxy User Mode DLL
The UIProxy source code can be downloaded from: Download UIProxy Source Code In Windows CE 6.0: Using UIProxy I discussed how to use CeCallUserProc() and the UIProxy. I showed some simple code for displaying a very simple MessageBox(). For this post, I thought that it would be interesting to flesh that out a little more and create a user mode DLL that wraps MessageBox() and allows the driver to do everything with MessageBox() that it might do if it was calling it directly. Almost everything, except ......

Posted On Saturday, January 10, 2009 8:15 PM | Comments (0)

Windows CE 6.0: Using UIProxy
Starting with Windows CE 6.0 kernel mode drivers cannot call User Interface (UI) functions. To overcome this Windows CE 6.0 provides the UIProxy and a new function, CeCallUserProc(). Kernel mode drivers can call CeCallUserProc() to request that a user mode dll be loaded and a function in the dll be called. When writing the driver, also write the user mode dll and provide functions that will present a UI for the driver. Luca Calligaris was nice enough to provide an example function in response to ......

Posted On Saturday, January 10, 2009 6:02 PM | Comments (0)

What is Windows CE?
Mike Hall at Microsoft recently posted a short video featuring Dion Hutchings, Technical Product Manager, talking about what Windows CE is. See Windows Embedded Blog : What is Windows CE ? - Here's Dion with the answer. to view the video. The wearable device that Dion shows is a Eurotech Zypad, The ZYPAD WL 11XX Wrist Worn Personal Computer is a powerful computing device designed to be worn comfortably on the user’s wrist for hands-free operation. The wearability and hands-free operation of the ZYPAD ......

Posted On Thursday, January 8, 2009 10:55 AM | Comments (0)

Summary of Registry Posts
Summary of Registry Posts Post of Interest to End Users and Software Engineers Windows CE: Editing the Registry A discussion about the registry editors available for Windows CE devices. Posts of Interest to Platform Builder Users Platform Builder: Automatically Flushing the Registry on Changes A discussion about the configuring filesys to automatically flush the registry when changes occur. Platform Builder: Managing the Registry A discussion about configuring adding and removing registry settings ......

Posted On Wednesday, January 7, 2009 8:38 PM

Summary of BIB File Posts
Posts About BIB Files Platform Builder: Error: Ram Start Overlaps ROM Binary A discussion about the warning/error that occurs if the space allocated for the OS image is too small. Platform Builder: Config.bib A discussion about configuring the OS using config.bib. Platform Builder: Handling Noncontiguous RAM A discussion of ways to configure a system that has noncontiguous RAM. Platform Builder: Fmerge Tips and Tricks A discussion of configuring files processed by fmerge, including bib files. Copyright ......

Posted On Tuesday, January 6, 2009 9:17 PM

Windows CE: Preventing Multiple Instances of an Application
There is often a good reason to allow only one instance of an application to run at any time. One example of this is the serial debug menu application that I present in Windows CE: Serial Debug Menu Summary. If that application were to have more than one instance the results would be unpredictable, unless you count user confusion. The input would randomly go to instance of the application based on which instance looked for input first. One way to prevent multiple application instances is to use a ......

Posted On Tuesday, January 6, 2009 8:57 PM | Comments (0)

Windows CE: Get Process Name using GetModuleFileName()
Sometimes there is value in determining an application name or folder from within the application. The application can use this to display the application name in the title bar, or even change behavior based on the name. GetModuleFileName() fills in a string with the path and filename of the application. The following code fragment uses the hInstance passed into WinMain() to get the application path and filename. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, ......

Posted On Tuesday, January 6, 2009 8:43 PM | Comments (2)

Platform Builder: StallExecution() vs Sleep()
StallExecution() and Sleep() are two ways to add a delay to a driver. But they delay in different ways so be cautious when selecting one of them. StallExecution() is a CEDDK function, so it is not easily accessible outside of Platform Builder. There is a good reason for that. StallExecution() takes as an argument the number of microseconds to delay. Since Windows CE uses a millisecond timer, there is no way to block for a number of microseconds. That means that StallExecution() must run continuously ......

Posted On Sunday, January 4, 2009 10:36 PM | Comments (0)

Luca Calligaris Receives the Microsoft Most Valuable Professional (MVP) Award
A colleague of mine, Luca Calligaris, in our Eurotech Italy office just received the MVP award for his work answering questions in the Windows CE newsgroups. Luca has been working with Windows CE for several years. He has been instrumental in getting several Windows CE products to market. Luca has is a Microsoft Technology Specialist having passed the Windows Embedded CE 6.0 Developer exam. Welcome to the MVP program Luca. The Eurotech Press Release can be found at: Eurotech Developer Earns Microsoft ......

Posted On Friday, January 2, 2009 6:01 PM | Comments (4)

Platform Builder: KernelRelocate()
KernelRelocate() copies initialized global variables to RAM, and sets uninitialized global variables to zero. KernelRelocate() is called from both the bootloader and the kernel. If you are more familiar with writing applications that run within an Operating System (OS) then needing KernelRelocate() is different. When you run an application within an OS, initialization of global variables is automatically performed for the application by the OS. But, the bootloader and the kernel are the OS, so they ......

Posted On Friday, January 2, 2009 1:32 PM | Comments (0)

Platform Builder: Running without a Bootloader
There was a question about running Windows CE without a bootloader in the Platform Builder newsgroup this morning. The poster suggested that KITL required a bootloader and asked if the OS required a bootloader in general. The simple answer, and the one that I replied with, is no. The OS does not require a bootloader. KITL does not require a bootloader. But, the BSP may require a bootloader. Without looking at any specific BSP, here are some of the reasons that a BSP might require a bootloader. · ......

Posted On Friday, January 2, 2009 11:12 AM | Comments (6)

Platform Builder: Automatically Flushing the Registry on Changes
I have discussed flushing the registry from applications before in Windows CE: Persisting Registry Changes from an Application. It is possible to set up the file system to automatically flush the registry when using hive registry. The system will automatically flush the registry when the system suspends. Filesys can be configured to flush the registry when changes occur by setting some registry values. [HKEY_LOCAL_MACHINE\System\... “SpawnThread"=dword:1 "FlushPriority256"=dword:FF ......

Posted On Thursday, January 1, 2009 10:43 PM | Comments (4)

Platform Builder: Error: Ram Start Overlaps ROM Binary
In embedded systems, like Windows CE, it is possible to have more bytes in the Operating System (OS) than there is space to store the OS on the device. It is also possible to have more bytes in the OS than you have allocated for saving the OS on the device. The first could be a bigger problem than the second. The Board Support Package (BSP) contains a file that allocates space for the OS. The file is config.bib (for more on config.bib see Platform Builder: Config.bib.) The space for the OS is allocated ......

Posted On Thursday, January 1, 2009 8:25 PM | Comments (0)