Listing Loaded Devices in Windows CE 5 or Above

by Krishnaraj Varma on September 18, 2008

Download the source code

The APIs FindFirstDevice and FindNextDevice can be used to search for a device currently loaded in Windows CE 5.0 or above. These APIs are not available in versions prior to Windows CE 5.0. The following are the syntax:

HANDLE FindFirstDevice(DeviceSearchType searchType,LPCVOID pvSearchParam,PDEVMGR_DEVICE_INFORMATION pdi);
BOOL FindNextDevice(HANDLE h,PDEVMGR_DEVICE_INFORMATION pdi);

If successful the FindFirstDevice returns a device handle which can be used for subsequent FineNextDevice. The first parameter is the device type which can be one of the following:

DeviceSearchByLegacyName
DeviceSearchByDeviceName
DeviceSearchByBusName
DeviceSearchByGuid
DeviceSearchByParent

The second parameter is the additional search parameter which depends of the device type specified. To search all devices we can use “*” as the search parameter. The third parameter is a pointer to DEVMGR_DEVICE_INFORMATION structure which will be filled with the details of the devices found.

The FindNextDevice returns TRUE if there are more devices to find otherwise returns FALSE. The first parameter is the HANDLE returned by the FindFirstDevice and second parameter is a pointer to the DEVMGR_DEVICE_INFORMATION structure.

The following code enumerate all devices and add the details to a ListCtrl.

HANDLE hDevice = NULL;
DeviceSearchType eSearchType = DeviceSearchByLegacyName;
DEVMGR_DEVICE_INFORMATION sInfo = {0};

sInfo.dwSize = sizeof(DEVMGR_DEVICE_INFORMATION);
hDevice = FindFirstDevice(eSearchType,TEXT("*"),&sInfo);

int nItem = 0;
int nListItem = 0;

if(INVALID_HANDLE_VALUE == hDevice)
return;

BOOL bContinue = TRUE;

while(bContinue)
{
nListItem = pList->InsertItem(nItem,sInfo.szLegacyName);

pList->SetItemText(nItem,1,sInfo.szDeviceName);
pList->SetItemText(nItem,2,sInfo.szDeviceKey);
pList->SetItemText(nItem,3,sInfo.szBusName);

++nItem;

bContinue = FindNextDevice(hDevice,&sInfo);
}

FindClose(hDevice);

{ 0 comments }

Listing Processor Features on Windows Mobile 5 or Above

by Krishnaraj Varma on September 17, 2008

Download the source code

We can use IsProcessorFeaturePresent to retrieve processor features the syntax of the API is:

BOOL IsProcessorFeaturePresent(DWORD dwProcessorFeature);

The dwProcessorFeature is the feature we want to check whether it is supported or not. There are different #defines in Winnt.h header file. These #defines depends on the processor being compiled. If you are using compiling for ARM processor you will get all the #defines of ARM processor. I compiled it for ARM processor. The other #defines are copied from Winnt.h to Features.h header file.

{ 0 comments }

Remote Application Start in Windows CE

by Krishnaraj Varma on September 16, 2008

Download the source code

CeStartProcess API can be used to start an application in Windows CE machine from a remote PC. To start an application first initialize RAPI using CeRapiInit or CeRapiInitEx and call this API with the name of the application. The sample application also uses CeGetSystemInfo and CeGetVersionEx APIs to get the system information and version.

{ 0 comments }

How to soft reset Windows Mobile programmatically

by Krishnaraj Varma on September 14, 2008

We can use the API SetSystemPowerState to reset the Windows Mobile device. The following code resets the device.

#include
#include

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
if(IDYES == MessageBox(NULL,TEXT("Are you sure to reset the device?"),TEXT("Reset"),MB_YESNO | MB_ICONQUESTION))
{
SetSystemPowerState(NULL,POWER_STATE_RESET,0);
}
return (int)0;
}

We can use following values instead of POWER_STATE_RESET
POWER_STATE_ON
POWER_STATE_OFF
POWER_STATE_CRITICAL
POWER_STATE_BOOT
POWER_STATE_IDLE
POWER_STATE_SUSPEND
POWER_STATE_RESET

The last parameter can be 0, POWER_FORCE or POWER_DUMPDW. The POWER_FORCE parameter indicates the state change is urgent, and the POWER_DUMPDW will generate Dr. Watson report.

Please note that some of the power state may not work in all the platforms. Different platforms may restrict the use of some of the power states

{ 0 comments }

Getting Network Adapter Information in Windows Mobile

by Krishnaraj Varma on September 14, 2008

Download the source code

The API GetAdaptersInfo or GetAdaptersAddresses can be used to get Network Adapter information. We can retrieve information like Adapter Name, Description, IP Address, Mask, DNS, etc… Here is a sample application that use GetAdapterInfo API to retrieve network information. The application screen looks like this:
Adapterinfo 225x300
The application retrieves this information and displays it in an owner draw list box.

{ 0 comments }

Remote Display For Windows Mobile 5 or above

by Krishnaraj Varma on September 14, 2008

Download the source code

As I already posted here, ActiveSync IP address 169.254.2.1/169.254.2.2 can be used to create socket based application. Here is an application that makes use of this; this application displays the Windows Mobile desktop on a remote computer. You can also take the screen shots. The screen can be saved to JPEG or PNG files, these are the only supported picture formats now. But you can extent this by creating an output plug-in DLL.

There are two components in this application, Mobile Server which runs on the mobile device and Client Component which runs on the PC. The mobile server listens on port 8082 which is configurable. The client application connects to this server.

When connected to the mobile server, client application sends MS_CMD_SCREENSHOT command every 100 milliseconds and receives the screen data in compressed form. The client uncompresses the data and displays it on the screen. The mobile server application received commands from the client and based on the command it receives sends the data to the client. As of now the only command supported is MS_CMD_SCREENSHOT which sends the screen data. The command structure is defined as


typedef struct __MS_CMD_TAG__
{
int nCommand;
int nDataSize;
}MS_CMD

The nCommand member specifies the command and nDataSize member specifies the size of additional data in bytes. This member is reserved for future use and is not used now.

The screen data format is:


typedef struct __MS_SCREEN_DATA_TAG__
{
int nWidth;
int nHeight;
int nBPP;
int nLineWidth;
int nCompressedSize;
int nDataSize;
}MS_SCREEN_DATA

The nWidth, nHeight members are width and height of the screen data respectively. The nBPP member is the bits-per-pixel of the screen data. The nLineWidth member is the length of the scan line of the screen data. nCompressedSize represents the compressed data. nDataSize is the uncompressed size.

The compressed data is send after the sending the MS_SCREEN_DATA structure, so the total size of the data will be nCompressedData + sizeof(MS_SCREEN_DATA).

The client application uses Output Plug-in for saving the screen shots. There are two output plug-in now, JPEG plug-in and PNG plug-in. You can extend this by creating Output Plug-in. The plug-in exports only one function GetPluginInterface which returns a pointer to IOutputPlugin which is defined as:


class COutputPlugin
{
public:
virtual LPCTSTR GetFileName() = 0;
virtual LPCTSTR GetPluginName() = 0;
virtual LPCTSTR GetDescription() = 0;
virtual long GetVersion() = 0;
virtual LPCTSTR GetFilterString() = 0;
virtual LPCTSTR GetExtension() = 0;

virtual int SaveImage(const char* lpszFile,BITMAPINFO* pInfo,BYTE* pBytes) = 0;
virtual void Release() = 0;
};

typedef COutputPlugin IOutputPlugin;

The class is simply and self-explanatory.

The application works well on my HTC TyTN II mobile and is not tested on any other mobile. Also this application will not work with the Emulator.

{ 0 comments }

Very Simple Notepad for Windows Mobile

by Krishnaraj Varma on September 12, 2008

Download the source and setup cab

This is a very simple notepad application for Windows Mobile 5 or above. There are some commercial and free notepad application available which are far more feature rich. But they don’t come with source code. This one comes with full source code.

There is only one point of interest in this application, Font Dialog. Windows Mobile doesn’t have any default font dialog. But we can use EnumFontFamiliesEx to enumerate fonts. The font dialog in this application use the above API to enumerate the installed fonts.

{ 0 comments }

ActiveSync and IP Address

by Krishnaraj Varma on August 31, 2008

Just a small piece of information: if you are using WM5 or above and ActiveSync 4.2 or above, the device will have the IP address 169.254.2.1 and the computer will have the IP address 169.254.2.2. We can use sockets to send and receive data between mobile device and computer.

{ Comments on this entry are closed }

Task Manager for Windows Mobile 5 or above

by Krishnaraj Varma on August 20, 2008

Download source code and setup cab

Using ToolHelp32 APIs for Windows Mobile we can enumerate processes, modules, heaps, etc… First we have to call CreateToolhelp32Snapshot API. This creates a snapshot of the current state of the system and returns a handle. We can use this handle to enumerate processes, modules, heaps, threads, etc…

The TaskManager application is written using ToolHelp32 APIs. This is a normal MFC dialog application. The running processes are listed in a ListView. Double clicking on an entry will open another dialog and display the modules loaded by the particular process.

A special thanks to Brian P. Adams for his article on how to calculate the memory used by a process.

{ 0 comments }

Changing Display Orientation in Windows Mobile

by Krishnaraj Varma on August 18, 2008

Download the source code

To change the display orientation of a Windows Mobile device, we can use the API ChangeDisplaySettingsEx. The syntax of the ChangeDisplaySettingsEx API is

LONG ChangeDisplaySettingsEx(LPCTSTR lpszDeviceName,LPDEVMODE lpDevMode,HWND hwnd, DWORD dwflags,LPVOID lParam);

The first parameter is the name of the device we want to change, we can use EnumDisplayDevices API to enumerate the devices. The second parameter is a pointer to the DEVMODE structure. It is very impotent to set the dmSize member to the size of the DEVMODE structure. Other members can be used to get and set the display properties. The third parameter is should be NULL and is reserved for future use. The last parameter dwFlags can contain one of the following values

CDS_FULLSCREEN, CDS_GLOBAL, CDS_NORESET, CDS_RESET, CDS_SET_PRIMARY, CDS_TEST, CDS_UPDATEREGISTRY, CDS_VIDEOPARAMETERS.

The dmDisplayOrientation member of the DEVMODE structure is used to get and set the display orientation property. This member can have one of the following values, DMDO_0, DMDO_90, DMDO_180, DMDO_270. To find out the supported Screen Orientations we set the dmFields member of the DEVMOE to DM_DISPLAYQUERYORIENTATION value and call the API. If the call is successful the dmDisplayOrientation of the DEVMODE will contain the supported modes. We can perform bit-wise operation to find the supported modes.

The sample application displays four radio buttons and clicking on these buttons will change the screen orientation. This is created using Microsoft Visual Studio 2008.

{ 0 comments }