Pocket News - Newsgroup reader for Windows Mobile

A few of you who know me probably have seen me from the Mobility community, MSDN Forums or the Newsgroups. I love helping out in the Newsgroups, I had so much fun doing so that I needed an application where I can do so while I’m on the go. Being the nerd that I am, my first reaction to this was that I needed to write a mobile newsgroup reader. I actually did before ever checking that a few of them already existed! Oh well, it was fun to write. I used the application a lot, especially while waiting in the airport, or for the train, or wherever that time feels like it stopped.

I decided to share this application to the public and publish it on CodePlex. If you’re interested in the source code or if you want to contribute to the project then check it out at http://pocketnews.codeplex.com

Unfortunately the application misses some basic features that any messaging application should have like a drafts folder. Maybe some day I can pull myself together to finish it up, or maybe some one out there who loves the Newsgroups just as much as I do would want to contribute some time and code :)

SQLCE Code Generator

Some time ago, I started a hobby project for generating data access layer code for SQL Compact Edition databases. I managed to get as far as creating a custom tool and generating a code behind data access layer file (currently only in C#) for every table in the database.

I’m having a bit of a hard time finding the time to work on the project so I published it on CodePlex. If you’re interested in the source code or if you want to contribute to the project then check it out at Github

How to toggle the Wi-fi radio

I had a task to complete today where I was to create an application to toggle the Wi-Fi radio. I had two major requirements for this task; I was supposed to not spend more an hour on this and it must run on older devices running Pocket PC 2003 (or older)

This is what I came up with, 1 function (the entry point) and it uses only 3 power management API calls; GetDevicePower, DevicePowerNotify, and SetDevicePower

Basically I spent most of the time finding the device name for the wireless device. It seems to be pretty used for Intermec devices as I tested it on 3 different devices (or it could also be that only those 3 devices used the same device name)

Anyway, here’s the code (works only for Intermec devices):

#include <windows.h>
#include <pm.h>
#define INTERMEC_WIFI_DEVICE    L"{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\BCMCF1"
int _tmain(int argc, _TCHAR* argv[])
    GetDevicePower(INTERMEC_WIFI_DEVICE, POWER_NAME, &state);
    CEDEVICE_POWER_STATE newState = (state == D0) ? D4 : D0;
    DevicePowerNotify(INTERMEC_WIFI_DEVICE, newState, POWER_NAME);
    SetDevicePower(INTERMEC_WIFI_DEVICE, POWER_NAME, newState);

Normally when I experiment with the platform SDK, I just create native console applications and test how the function works. Since my application was simple and didn’t need a UI, I just shipped it in native code.

But for the sake of sharing knowledge I ported my tiny application to the .NET Compact Framework. Here’s the code (works only for Intermec devices):

[DllImport("coredll.dll", SetLastError = true)]
static extern int DevicePowerNotify(string name, CEDEVICE_POWER_STATE state, int flags);
[DllImport("coredll.dll", SetLastError = true)]
static extern int SetDevicePower(string pvDevice, int dwDeviceFlags, CEDEVICE_POWER_STATE DeviceState);
[DllImport("coredll.dll", SetLastError = true)]
static extern int GetDevicePower(string pvDevice, int dwDeviceFlags, ref CEDEVICE_POWER_STATE pDeviceState);
    PwrDeviceUnspecified = -1,
    D0 = 0,
    D1 = 1,
    D2 = 2,
    D3 = 3,
    D4 = 4,
    PwrDeviceMaximum = 5
const int POWER_NAME = 0x00000001;
const string ADAPTER_NAME = "{98C5250D-C29A-4985-AE5F-AFE5367E5006}\\BCMCF1";
static void Main()
    GetDevicePower(ADAPTER_NAME, POWER_NAME, ref state);
    DevicePowerNotify(ADAPTER_NAME, newState, POWER_NAME);
    SetDevicePower(ADAPTER_NAME, POWER_NAME, newState);

There are smarter, better, and non-OEM specific ways to do this, both in native and managed code. In native code, one can use the wireless device functions (GetWirelessDevice, ChangeRadioState, FreeDeviceList) in the Wireless Device Power Management API (OSSVCS.dll) as described in this article. And in managed code, one can take advantage of the OpenNETCF Smart Device Framework.

Here’s an example of how to use the OpenNETCF.WindowsMobile namespace in the Smart Device Framework for toggling the state of wireless devices:

using System.Linq;
using OpenNETCF.WindowsMobile;
static class Program
    static void Main()
        var wifi = from radio in Radios.GetRadios()
                   where radio.RadioType == RadioType.WiFi
                   select radio;
        foreach (var radio in wifi)
            radio.RadioState = (radio.RadioState == RadioState.On) ? RadioState.On : RadioState.Off;

I hope you found this article useful