apitips

Identifying Your Windows Mobile Device

Sometimes your application will need to know what type of device it’s running on.  One app I’ve been working on lately needs to get some configuration information from a server, but in order to give back an accurate config the server needs to know exactly which handset it’s dealing with.  If the user were using the handset’s browser to make the connection the server would be able to figure out the model of the handset from the User-Agent header supplied by the browser, but our application is making those connections directly via calls to the HTTP functions in the WinInet library.  In this case we need to figure out what device the app is running on through the API.

Luckily Microsoft anticipated this need and provided a way for us to get the information we need via a call to the SystemParametersInfo function.  This function can actually tell you all sorts of things about the platform your app is running on, and lets you set many parameters as well.  For a full list of what it can do, check out the details on MSDN.  In order to solve our problem we only need to call it two ways:

TCHAR modelBuffer[64];

TCHAR manufacturerBuffer[64];

BOOL result;

result = SystemParametersInfo(SPI_GETOEMINFO, modelBuffer, 64, 0);

result = SystemParametersInfo(SPI_GETPLATFORMMANUFACTURER, manufacturerBuffer, 64, 0);

These calls will fill the two buffers with the manufacturer and model information for the Windows Mobile handset your application is running on.  The third parameter specifies how many characters your buffer can hold.  The final parameter is unused when we’re only reading information, so we just set it to zero.  If the function returns a true value then you can expect that your buffer will now contain a string identifying your handset.  You can then pass that information on to a server through calls to WinInet functions or just use it locally.

Tags: , , ,

Friday, February 6th, 2009 Windows Mobile No Comments