Tuesday, March 22, 2005

How I Beat One of The Residents at His Own Game

Jay Clem: What’s truly amazing about all of this Sid is that some guy who’s been a fan for 25 years beat The Residents’ own Stu Sucliffe at his own game.

Sid Powell (of RAO Studios, Houston): That may indeed be a wonderment, Mr. Clem. But what I really want to know is who really cares who’s hands this infantile garbage ends up in?

Jay Clem: Well, Sid, it may not much matter to a crusty old fart like you, but there are in fact hundreds of die hard fans out there who would pay top dollar to get their hands on these recordings. Why, the very essence of the Residents legend rests on the mystery surrounding these works.

Sid Powell (of RAO Studios, Houston): Well, then, Mr. Clem, if these artistic endeavors are indeed so important to your charges, The Residents, then why is it that a fan unbeknownst to them has managed to execute a classic switch and offer up to one of their former number that which is so devoutly regarded as sacred and kept out of reach of their fans?

Jay Clem: It just goes to show that the Residents’ fans are in fact a force to be reckoned with, and that even the Residents themselves hold them in such high esteem specifically because of their power to unveil The Residents deepest secrets. Which is why Mr. Sirois of the Frozen North has agreed to do no less than urge his erstwhile bandmates to invite the good Mr. Burdick to participate in some meaningful way in the soon to be announced tour of the Animal Lover CD to be released imminently.

Sid Powell (of RAO Studios, Houston): And perhaps even to take the place of that abominably bad singer once he decided it’s finally time to hang up his skull and get a real job?

Jay Clem: Well, Sid, I didn’t say yes, but I most certainly didn’t say no…

Thursday, March 10, 2005

Embedded Systems Conference Attendees - Thank You!!

Just a quick post to say thank you to all of you who attended my presentation "Building Internet Applications with Microsoft's .NET Compact Framework" today at the Embedded Systems Conference in San Francisco. It is always a pleasure to speak with an enthusiastic, interested audience with great questions and comments. I hope the presentation was as useful and informative for you to attend as it was enjoyable for me to give.

Wednesday, March 09, 2005

Residential Musings on My Big Four Oh...

Eyeballs on T-Shirts, coffee mugs, beer steins... Pretty much anything I own has got a bizarre eyeball with a top hat icon on it. What is up with this?

On this, my big 40, I figured it was high time take a break from the code related stuff and talk a little about one of my longest favorite groups. Not that they have always been "the" favorite, but they have certainly been "a" favorite for as many birthdays as I care to remember.

The Residents are the world's most famous unknown, anonymous band. 4 or 5 guys or gals teamed up in the late 60's to set the musical world on its proverbial ear. With no talent or musical ability to speak of, these crazies started making odd cacophonous sounds and demo tapes primarily to suite their own interest in recording. For the better part of 5 years, none of the material they produced was released to the public. To this day, 33 years later, most of this early material has never been officially released. The Residents themselves claim this is because the material was awful. This hasn't stopped digging around, and some true die hards (myself included) have managed to come up with two of the four tapes / albumns allegedly recorded but never released. More information about thes e prehistoric recordings can be found at the excellent Residents informational website at this location.

Some say that turning 40 is supposed to be depressing. But after being a Residents fan for nearly 25 years, today, the day I turned the big 40, I finally landed a copy of the fourth and final unrelease tapes. What a gift!! More later...

Sunday, March 06, 2005

Embedded Systems Conference Code Samples

Here are the code samples associated with my presentation "Building Internet Applications with Microsoft's .NET Compact Framework" given on March 10, 2005 in San Francisco.

These samples are posted without warranty of any kind. They were configured to run on the demo laptop I used during the presentation, so some tweaking of URLs etc. might be required to get them to run in your environment. In short, these samples are posted here more as walk through examples, as they were used at the conference, than as complete production code samples. Also, two of the samples, the managed code database example and the managed servicesclient sample depend on server-side ASP.NET applications to serve content. The code and configuration information for the web components of these applications are available upon request. Just post a comment to this entry and we can get in touch.

With these caveats in mind, there are two zip files availabile. The first contains all of the native code samples presented:
Native Code Samples

The second contains the mananaged code samples:
Managed Code Samples


Enjoy!!

Tuesday, March 01, 2005

Programatically Powering PocketPC Screen On and Off

Another common request is how to power the Pocket PC screen on or of programatically. The solution to this problem is the ExtEscape API, with the SETPOWERMANAGEMENT flag set. Note that implementing support for this particular ExtEscape capability is OEM dependent. Therefore, it may not work on all devices. This is why we call ExtEscape with QUERYESCSUPPORT at the beginning of the PowerScreen function call.

#define QUERYESCSUPPORT 8

//The following are unique to Windows CE
#define GETVFRAMEPHYSICAL 6144
#define GETVFRAMELEN 6145
#define DBGDRIVERSTAT 6146
#define SETPOWERMANAGEMENT 6147
#define GETPOWERMANAGEMENT 6148

typedef enum _VIDEO_POWER_STATE {
VideoPowerOn = 1,
VideoPowerStandBy,
VideoPowerSuspend,
VideoPowerOff

} VIDEO_POWER_STATE, *PVIDEO_POWER_STATE;

typedef struct _VIDEO_POWER_MANAGEMENT {
ULONG Length;
ULONG DPMSVersion;
ULONG PowerState;
} VIDEO_POWER_MANAGEMENT, *PVIDEO_POWER_MANAGEMENT;

void PowerScreen(BOOL bPowerOn)
{
VIDEO_POWER_MANAGEMENT vpm, vpmQuery;
BOOL bCurrentState = FALSE;

int iESC = SETPOWERMANAGEMENT;
if (ExtEscape(g_hdc, QUERYESCSUPPORT,
sizeof(int), (LPCSTR)&iESC,
0, NULL)==0)
return;


//Prevent the screen manager from
//attempting to turn the screen on if it's
//already on, and from turning the

//screen off if it's already off.

//This is a problem on some platforms,

//such as the iPAQ H3800 PocketPC 2002 platform.

memset(&vpm, 0, sizeof(vpm));
vpm.Length = sizeof(vpm);
vpm.DPMSVersion = 0x0001;

memset(&vpmQuery, 0, sizeof(vpmQuery));
vpmQuery.Length = sizeof(vpmQuery);
vpmQuery.DPMSVersion = 0x0001;

//Query the current screen power status

::ExtEscape(g_hdc, GETPOWERMANAGEMENT,
vpm.Length, (LPCSTR)&vpm,
vpmQuery.Length, (LPSTR)&vpmQuery);

bCurrentState =

((vpmQuery.PowerState > VideoPowerOn) ? FALSE : TRUE);

if (bPowerOn == bCurrentState)
return;

memset(&vpm, 0, sizeof(vpm));
vpm.Length = sizeof(vpm);
vpm.DPMSVersion = 0x0001;
vpm.PowerState = (bPowerOn ? VideoPowerOn : VideoPowerOff);

::ExtEscape(g_hdc, SETPOWERMANAGEMENT,
vpm.Length, (LPCSTR)&vpm, 0, NULL);
}



wAppearances Code Sample Archive

Now that I'm blog compliant, I should post the link to all of my previous code samples here. So instead of having to grovel around both here and in the wAppearances web site, you can use my blog as a one stop shop for all Windows CE code samples, tips, and tricks I make available.

Here is the link to my old code sample archive:

Code Sample Archive

Determining 802.11 Signal Strength for Pocket PC

A very common request from Pocket PC developers is the ability to query the signal strength of an 802.11 wireless network signal being received by a WiFi enabled Pocket PC device. Here is some code that accomplishes this task for you.

This code basically queries the RSSI (Received Signal Strength Indicator) via the NDIS protocol. In your application, you call the GetFirstRFEthernetSignalStrength function to kick this all off as follows:

int nStrength = 0;
int nQuality = 0;
GetFirstRFEthernetSignalStrength(&nStrength, &nQuality);

The nStrength valule returned can then be used by your application to update a signal strength indcator such as a track bar or other UI element.




#include <ntddndis.h>
#include <nuiouser.h>
#include <winioctl.h>
#include <iphlpapi.h>

HRESULT GetSignalStrength(
TCHAR *ptcDeviceName,
int* piSignalStrength,
int* piSignalQuality
)
{
PNDISUIO_QUERY_OID queryOID;
DWORD dwBytesReturned = 0;
UCHAR QueryBuffer[sizeof(NDISUIO_QUERY_OID)
+sizeof(DWORD)];
HANDLE ndisAccess = INVALID_HANDLE_VALUE;
BOOL retval;
HRESULT hr;

// Attach to NDISUIO.
ndisAccess = CreateFile( NDISUIO_DEVICE_NAME,
0, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
INVALID_HANDLE_VALUE );
if ( ndisAccess == INVALID_HANDLE_VALUE )
return E_FAIL; // ????

// Get Signal strength
queryOID = (PNDISUIO_QUERY_OID)&QueryBuffer[0];
queryOID->ptcDeviceName = ptcDeviceName;
queryOID->Oid = OID_802_11_RSSI;

retval = DeviceIoControl( ndisAccess,
IOCTL_NDISUIO_QUERY_OID_VALUE,
(LPVOID) queryOID,
sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD),
(LPVOID) queryOID,
sizeof(NDISUIO_QUERY_OID) + sizeof(DWORD),
&dwBytesReturned,
NULL);
if( retval && piSignalStrength && piSignalQuality )
{
hr = S_OK;
*piSignalStrength = *(DWORD *)&queryOID->Data;

//Here's Microsoft's interpretation
//of the return value
if(*piSignalStrength < -90)
*piSignalQuality = 0; // No signal
else if(*piSignalStrength < -81)
*piSignalQuality = 1; // Very low
else if(*piSignalStrength < -71)
*piSignalQuality = 2; // Low
else if(*piSignalStrength < -67)
*piSignalQuality = 3; // Good
else if(*piSignalStrength < -57)
*piSignalQuality = 4; // Very good
else
*piSignalQuality = 5; // Excellent
}
else
{
hr = E_FAIL;
}

CloseHandle( ndisAccess );

return hr;

}

BOOL GetFirstRFEthernetSignalStrength(
int* pSignalStrength,
int* pSignalQuality
)
{
BOOL retval = FALSE;

// Get the size of the adapters list.
DWORD size = 0;

GetAdaptersInfo( NULL, &size );

// Allocate space for the list.
IP_ADAPTER_INFO *info =
(IP_ADAPTER_INFO*)new char[ size ];

DWORD err;
if ((err = GetAdaptersInfo(info, &size ))
== NO_ERROR )
{
IP_ADAPTER_INFO *cinfo = info;
while ( cinfo )
{
// Check the interface media type for
// Ethernet, which both
// standard Ethernet and RF Ethernet will return.
if ( cinfo->Type == MIB_IF_TYPE_ETHERNET )
{
TCHAR wName[ MAX_ADAPTER_NAME_LENGTH + 4 ];
MultiByteToWideChar( CP_ACP, 0,
cinfo->AdapterName, -1,
wName,
sizeof( wName ) / sizeof( wName[ 0 ] ) );

// Try to get the signal strength.
//If it works, we
// return the information.
//If not, we move on.
if ( GetSignalStrength( wName,
pSignalStrength, pSignalQuality ) == S_OK )
{
retval = TRUE;
break;
}
}

// Go to the next adapter in the list.
cinfo = cinfo->Next;
}
}

// Don't forget to delete the allocation.
delete [] info;

return retval;
}

Embedded Systems Conference Slides and Proceedings Paper

I will be presenting at the Embedded Systems Conference in San Francisco Thursday March 10 at 2:00 PM. The title of my presentation is "Building Internet Applications with Microsoft's .NET Compact Framework".

If you are interested in the PowerPoint slides that go with this presentation, feel free to download them by clicking this link:
ESC Slides.

Also, the paper to be published in the conference proceedings for the conference can be found here:
Proceedings Paper

The code samples that I will be presenting at this session will follow shortly.