Download the source code
The RIL API RIL_GetAllOperatorsList retrieves all built-in known operators list. The API returns the operators list in an array of RILOPERATORNAMES structures. The structure is defined as:
typedef struct {
DWORD cbSize;
DWORD dwParams;
char szLongName[MAXLENGTH_OPERATOR_LONG];
char szShortName[MAXLENGTH_OPERATOR_SHORT];
char szNumName[MAXLENGTH_OPERATOR_NUMERIC];
char szCountryCode[MAXLENGTH_OPERATOR_COUNTRY_CODE];
} RILOPERATORNAMES;
The szLongName member contains the long name of the operator and szShortName contains the short name of the operator. The szNumName represents the numeric representation of the operator and the szCountryCode member represents the country/region code of the operator.
This function retrieves all known operators, to retrieve all available operators list use the API RIL_GetOperatorList. This function returns the list in an array of RILOPERATORINFO structures. The structure is defined as:
typedef struct {
DWORD cbSize;
DWORD dwParams;
DWORD dwIndex;
DWORD dwStatus;
RILOPERATORNAMES ronNames;
} RILOPERATORINFO;
The ronNames contains the operator details.
Download the source code
The TAPI function lineSetEquipmentState can be used to programmatically control the radio state. To change the radio state first initialize the TAPI and find the cellular line (line name is CELLTSP_LINENAME_STRING), then use the lineSetEquipmentState with appropriate flag. The syntax of the lineSetEquipmentState API is:
LONG WINAPI lineSetEquipmentState(HLINE hLine,DWORD dwState);
The hLine parameter is the cellular line handle. Second parameter dwState is the state of the radio and can be one of the following values.
LINEEQUIPSTATE_MINIMUM
LINEEQUIPSTATE_RXONLY
LINEEQUIPSTATE_TXONLY
LINEEQUIPSTATE_NOTXRX
LINEEQUIPSTATE_FULL
Most of the devices accepts only LINEEQUIPSTATE_MINIMUM and LINEEQUIPSTATE_FULL. The LINEEQUIPSTATE_MINIMUM will turn the radio off and LINEEQUIPSTATE_FULL will turn the radio on.
The sample application provided here displays the radio state and a button. Clicking the button will toggle the radio state.
Download the source code
Connection Manager is a Windows Mobile component that manages and monitors different types of network connections such as PPP, RAS, GPRS, etc… Connection Manager provides a set of native code APIs which can be used to establish voice and data connections. When an application requests a connection, the connection manager determines which is the optimal connection type and establishes the connection. The Connection Manager also tracks which connections are active and disconnect connections which are idle for a given period of time.
The Connection Manager supports two types of destination networks, Internet Network and Work Network. Internet Network is used to connect to the wider internet and Work Network is used to connect to the corporate network directly or through VPN connection. Before using the Connection Manager you have to configure these two network settings.
Following are some of the main parts of Connection Manager:
Connection Manager Application (ConnMgr.exe): When an application request a connection, the Connection Manager application determines the path to the target network. Once the Connection Manager found all the paths it requests the Connection Manager to determine the best connection to the target network.
Connection Planner (ConnPlann.dll): Connection Planner is responsible for determine the best path to the target network. Connection Planner uses Connection Manager Configuration Service Providers to find out the cost, bandwidth, etc… before deciding the best connection path. Connection Planner is also responsible for determining the priority of the connection. When a higher priority connection is made and if there is a lower priority connection is active, then Connection Planner disconnects the lower priority connection.
Connection Service Providers: These are dynamic link libraries (DLLs) that provide the connection information such as route and cost to the Connection Manager application and store this information. There are different connection service providers such as CSPNet, CSPProxy, CSPRas, CSPVoice, etc…
Connection Manager provides a set of native code APIs for the applications to request and manage network connection. An application can use these APIs to request a connection, register for status notification, etc… Following are some of the important Connection Manager APIs:
| ConnMgrConnectionStatus |
This function retrieves the status of the current connection. |
| ConnMgrEnumDestinations |
This function enumerates available networks. |
| ConnMgrEstablishConnection |
This function creates a connection request. |
| ConnMgrEstablishConnectionSync |
This function creates a connection request. |
| ConnMgrMapConRef |
This function maps a connection reference to its corresponding GUID. |
| ConnMgrMapURL |
This function maps a URL to the GUID of a destination network. |
| ConnMgrRegisterScheduledConnection |
This function registers a scheduled connection. |
| ConnMgrReleaseConnection |
This function deletes a specified connection request, potentially dropping the physical connection. |
| ConnMgrUnregisterScheduledConnection |
This function unregisters a scheduled connection. |
| ConnMgrRegisterForStatusNotification |
Registers a window handle for connection status notifications. |
For a complete list of Connection Manager APIs refer to the Connection Manager Function documentation
To enumerate the available network details ConnMgrEnumDestinations API is used. The syntax is defined as:
HRESULT WINAPI ConnMgrEnumDestinations(int Index,CONNMGR_DESTINATION_INFO *pDestInfo);
To enumerate all the available networks, an application calls this API with index 0 and increment until the API returns an error.
To establish a connection we can use the API ConnMgrEstablishConnection or ConnMgrEstablishConnectionSync. The syntax of the functions are:
HRESULT WINAPI ConnMgrEstablishConnection(
CONNMGR_CONNECTIONINFO *pConnInfo, HANDLE *phConnection);
HRESULT WINAPI ConnMgrEstablishConnectionSync(CONNMGR_CONNECTIONINFO *pConnInfo,
HANDLE *phConnection, DWORD dwTimeout, DWORD *pdwStatus);
The pConnInfo parameter is a pointer to the structure CONNMGR_CONNECTIONINFO and provides the information about the request. The phConnection parameter receives the handle of the connection when the connection is established. The dwTimeout specifies the timeout in millisecond for the connection establishment. The pdwStatus parameter specifies the status of the connection upon exit.
ConnMgrEstablishConnection is asynchronous in nature. It will request a connection and return immediately. The Connection Manager will post a message to the window handle specified by the hWnd member of the CONNMGR_CONNECTIONINFO structure . The uMsg member specifies what message should be used to send the status change notification. The wParam of the message will be the status of the connection. There are different status values defined in connmgr.h header file which describes the current status of the connection.
ConnMgrEstablishConnectionSync is synchronous in nature. It will request a connection and wait for specified time and return. Upon exit the pdwStatus will have the connection status.
The sample application provided here lists all available networks in a combo box. When connection is requested the selected network is used to establish the connection. The status of the connection will be displayed in a static text box. Hope this gives you an introduction to the Connection Manager APIs.
Download the source code
To enumerate installed fonts in Windows Mobile, we can use the APIs EnumFonts or EnumFontFamiliesEx. The EnumFontFamiliesEx API is preferred than EnumFonts. The syntax of the EnumFontFamiliesEx is:
int EnumFontFamiliesEx(HDC hdc,LPLOGFONT lpLogfont,
FONTENUMPROC lpEnumFontFamExProc,LPARAM lParam,DWORD dwFlags);
The first parameter is the handle to a Device Context. The second parameter s pointer to a LOGFONT structure. Only lfCharset, lfFaceName, lfPitchAndFamily members are important. The third parameter is pointer to the callback function which will be called for each font found while enumerating. Fourth an parameter is application defined value which will be passed to the callback function. Fifth parameter should be 0 and is not used.
The syntax of the callback function is:
int CALLBACK EnumFontFamExProc(CONST LOGFONT *,
CONST TEXTMETRIC *, DWORD, LPARAM);
The first parameter will be a pointer to ENUMLOGFONTEX structure which contains the font information. The second parameter is a pointer to the TEXTMETRIC structure which contains the attributes of the font. The third parameter is the type of the font which will be DEVICE_FONTTYPE, RASTER_FONTTYPE or TRUETYPE_FONTTYPE. The fourth parameter is the application defined lParam value.
The sample application presented here enumerate all the fonts installed in the device. The EnumFontFamiliesEx is called two times. First to get all the face name and second to enumerate all the fonts of each face name.
Download the source code
This part of the Using RAPI series explains how to enumerate files and folders of the connected device. In previous part I explained how to enumerate database on the connected device.
After creating the IRAPISession using the CreateSession, we can use the CeFindFirstFile and CeFindNextFile to enumerate all the files and folders. This will return the file information in CE_FIND_DATA structure. The CE_FIND_DATA is defined as:
typedef struct CE_FIND_DATA
{
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwOID;
WCHAR cFileName[MAX_PATH];
} CE_FIND_DATA;
The CeFindFirstFile’s first parameter is file pattern and second parameter is a pointer to CE_FIND_DATA structure which receives the information about the file. The function returns a find handle. The CeFindNextFile’s first parameter is the handle returned by the CeFindFirstFile and second parameter is a pointer to the CE_FIND_DATA structure. The function returns TRUE is a file is found otherwise FALSE.
The sample application presented here is a regular MFC application which lists all the folders in left pane and files in right pane. The application is created using Visual Studio 2008.
Download the source code
In the part 1 of Using RAPI series, I explained how to enumerate the connected device and get the details. This part of the series explains how to enumerate the database on the device.
When we enumerate the device using IRAPIDesktop::EnumDevices and IRAPIEnumDevices::Next we get a pointer to the IRAPIDevice that represents a particular device. The IRAPIDevice has a method CreateSession which is used to create a session. The syntax of CreateSession is:
HRESULT CreateSession(IRAPISession** ppISession);
This function create an IRAPISession which can be used to perform operations on the connected device. Once the session is created, you should call the CeRapiInit method of the IRAPISession interface. This will initialize the communication to the connected device. It is very important to call this method, otherwise all other methods will fail.
To enumerate all the mounted databases on the device, we can use the methods CeFindFirstDatabaseEx and CeFindNextDatabaseEx of the IRAPISession interface. The CeFindFirstDatabaseEx returns a handle to the enumeration. The CeFindNextDatabaseEx method returns a CEOID which is an identifier of the database. To get the information about the database we can call CeOidGetInfoEx method of the IRAPISession. This will return the information such as name, number of records, database type, etc… CeFindNextDatabaseEx function returns 0 when it is finished with the enumeration.
The sample application presented here lists all databases that are on the device memory and display the name and number of records. The application is created in Visual Studio 2008 using MFC. In the next part I will try to explain how to enumerate file system.
Download the source code
The RAPI2 library is used by the desktop applications to communicate to the connected Windows CE based devices. The desktop applications can perform actions such as create, edit or delete the file system, database or registry.
This article describes how to enumerate the connected devices and get information such as name, platform, etc… Next part of the series will describe how to manipulate the file system and database.
RAPI2 uses the ActiveSync application to communicate to the connected device. Users should install the ActiveSync in order to work with the RAPI2 library.
IRAPIDesktop
IRAPIDevice
IRAPIEnumDevices
IRAPISession
IRAPISink
IRAPIDesktop serves as the connection point container of all the devices. This interface is used to enumerate the connected devices. This interface has following methods:
HRESULT Advise(IRAPISink* pISink,DWORD* pdwContext);
HRESULT EnumDevices(IRAPIEnumDevices** ppIEnum);
HRESULT FindDevices(RAPIDEVICEID *pDeviceID,RAPI_GETDEVICEOPCODE opFlags,IRAPIDevice** ppIDevice);
HRESULT UnAdvise(DWORD dwContext);
The Advice method is used to register the IRAPISink interface to receive the device notifications. The pISink parameter is a pointer to an interface that implements the IRAPISink. The IRAPISink has two methods:
HRESULT OnDeviceConnected(IRAPIDevice* pIDevice);
HRESULT OnDeviceDisconnected(IRAPIDevice* pIDevice);
The OnDeviceConnected will be called when a device is connected and OnDeviceDisconnected will be called when a device is disconnected. Both methods has one argument. This is a pointer to the IRAPIDevice interface which represents the device connected or disconnected.
The EnumDevices method is used to enumerate connected device. This accepts one argument which is pointer to pointer to IRAPIEnumDevices interface. We can use this IRAPIEnumDevices interface to start enumerating the devices.
The FindDevices is used to find a particular device. The function accepts a Device ID and a RAPI_GETDEVICEOPCODE enumeration which will always be RAPI_GETDEVICE_NONBLOCKING. The third parameter is an out parameter which will be filled with IRAPIDevice interface.
The UnAdvise is used to cancel the already registered device notification.
The sample is a simple application that lists all the devices connected to the system. The application registers for the device notification and enumerate already connected devices. When a device is connected or disconnected the application add or delete the device from the connected device list.
In the next part, I will try to explain how to manipulate the file system and databases of the connected device.
Download the source code
Radio Interface Layer (RIL) is an interface between the radio hardware and the CellCore system. This is an abstraction layer which enables to create single driver modal for different radio hardware. For a more detailed information about RIL refer to my article Using Radio Interface Layer (RIL) to retrieve Cell Tower Information on Windows Mobile
When a call is coming, the RIL will call our NotifyCallback functon. The first call will be with RIL_NOTIFY_RING notification code. The it will be called with RIL_NOTIFY_CALLERID notification code. At this point the the lpData member will contain the pointer to the structure RILREMOTEPARTYINFO. The raAddress member contains the caller address (number).
The RIL function RIL_Hangup can be used to hangup a call. The behavior of this function is defined by the RIL driver component. The function hangups a data call if one is active or a voice call in one is present. If both are active at the time of calling, it will hangup the voice call.
The sample application presented here is a single document interface document using MFC. Upon receiving the RIL_NOTIFY_CALLERID, the application searches a database to see whether the number is present or not. If the number is present in the database it will hangup the call. Using the main user interface you can insert, edit or delete the numbers in the database.
To compile this sample you should install Windows CE. An evaluation copy can be downloaded from the Microsoft Windows CE website.
Download the source code
Control Panel application is normal DLL that exports one function CPlApplet. The system will load all control panel application that are in the Windows folder. The application should have the extension .CPL. The control panel application can be accessed from the Settings.
The syntax for the function CPlApplet is :
LONG APIENTRY CPlApplet(HWND hwndCPl,UINT uMessage,LPARAM lParam1,LPARAM lParam2);
This function will be called by the Settings application. The hwndCPL member will be main window of the controlling application. This can be used as a parent window. The uMessage parameter is the message that is passed to the application. The parameters lParam1 and lParam2 depends on the message parameter.
Below are the possible messages and their descriptions:
| CPL_INIT |
This message is the first message that will be send to the application. The application can initialize any resource for future use. The application should return TRUE if the initialization is successful otherwise FALSE. |
| CPL_GETCOUNT |
This is the second message passed to the application. Application should return the number if control panel application supported. A control panel DLL can support more that one application. |
| CPL_NEWINQUIRE |
This will be the third message passed to the application. The lParam1 will be the application number and the lParam2 will be a pointer to NEWCPLINFO structure. The application should fill the NEWCPLINFO structure with the information about the application such as name, description, icon, etc… The application should return 0 if successful otherwise a nonzero value. |
| CPL_STOP |
This message is passed to the application whenever the system is about the close the application. The application can perform any cleanup operation. A value of zero indicates success and nonzero value indicates failure. |
| CPL_EXIT |
This message is passed to the application when the system is about to free the control panel DLL. A value of zero indicates success and nonzero value indicates failure. |
The sample provided here is a simple control panel application that will just display the memory usage of the system using a message box. A real control panel application may create a dialog and allow the user to set/change some of the system properties.
Download the source code
I am working on creating an extension to the Windows Mobile HTTP server using ISAPI. I need to automatically capture still image without user action using DirectShow. I created a DLL using the Windows Mobile SDK sample CameraCapture. I think it is better to share this with you.