Remote Access Devices

Pocket PC supports using either a direct connection or a modem to establish a RAS connection. In order to determine what communication devices are available for dial-up, as well as what type they are, you can use the RasEnumDevices() function:

 DWORD RasEnumDevices(LPRASDEVINFO lpRasDevInfo, LPDWORD    lpcb, LPDWORD lpcDevices); 

The first parameter should point to a buffer that contains an array of RASDEVINFO structures, one for each RAS device connected. This is followed by lpcb, a pointer to a DWORD value that contains the size of the lpRasDevInfo buffer. When the function returns, it will contain the actual number of bytes that were copied into it. Finally, lpcDevices should point to a DWORD that contains the number of RASDEVINFO structures that were copied into the array.

Similar to RasEnumEntries(), before you call RasEnumDevices, you must set the dwSize member of the first RASDEVINFO structure in the lpRasDevInfo array to the size of RASDEVINFO.

The RASDEVINFO structure is defined as follows:

 typedef struct tagRasDevInfoW {    DWORD dwSize;    WCHAR szDeviceType[RAS_MaxDeviceType+1];    WCHAR szDeviceName[RAS_MaxDeviceName+1]; } RASDEVINFO; 

The dwSize member should be set to the size, in bytes, of a RASDEVINFO structure. The next two strings are the actual device identifiers. First is szDeviceType, a null-terminated string that specifies which type of RAS device is connected. On a Pocket PC, this can be set to either modem or direct. The last member, szDeviceName, will contain a null-terminated string with the actual device name.

For example, to enumerate through all of the RAS-capable devices, you could do the following:

 // Enumerate available RAS devices RASDEVINFO rasDevInfo[10]; DWORD dwReturn = 0; DWORD dwSize = sizeof(RASDEVINFO)*10; DWORD dwNumDevices = 0; memset(&rasDevInfo, 0, sizeof(RASDEVINFO)*10); rasDevInfo[0].dwSize = sizeof(RASDEVINFO); if(RasEnumDevices((LPRASDEVINFO)&rasDevInfo, &dwSize,    &dwNumDevices) != 0) {    MessageBox(NULL, TEXT("Could not enumerate Ras Devices"),    TEXT("RAS Error"), MB_ICONERROR|MB_OK);    return FALSE; } // Print out the list of available devices for(WORD wDevice = 0; wDevice<dwNumDevices; wDevice++) {    TCHAR tchRasDeviceInfo[256] = TEXT("\0");    wsprintf(tchRasDeviceInfo, TEXT("Name: %s\r\nType:%s"),       rasDevInfo[wDevice].szDeviceName,       rasDevInfo[wDevice].szDeviceType);    MessageBox(NULL,tchRasDeviceInfo, TEXT("RAS Devices"),       MB_OK); } 

Once you have established which device you are going to use, you may have to configure it for your communications session. To do so, you can manually set it up using the RasSetEntryDevConfig() function.



Pocket PC Network Programming
Pocket PC Network Programming
ISBN: 0321133528
EAN: 2147483647
Year: 2005
Pages: 90

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net