Direct Socket Connections
There are times where the communication requirements of your application go beyond the services that RAPI provides. The link that ActiveSync and RAPI use is built on TCP/IP. So if you want, it's fairly straightforward to establish a link between the PC and the device with sockets.To link two devices with sockets, you need the IP address of both devices. I just covered how the IDccMan interface can provide the IP address of the remote Windows CE device. This IP address is accurate if the ActiveSync connection is made over a network. However, if the connection is made via a serial or infrared link, the IP address reported is 127.0.0.1.On the device side, if the PC is connected via a serial or infrared link, the connected PC's IP address can be found by using gethostbyname, passing the name "ppp_peer". An example of this is shown here:struct hostent *phe;
SOCKADDR_IN pc_sin;
phe = gethostbyname ("ppp_peer");
if (phe) {
pc_sin.sin_addr.S_un.S_addr = *(DWORD *)phe->h_addr;
printf "PC addr: %s", inet_ntoa (pc_sin.sin_addr));
}
If ActiveSync is connected over an Ethernet link, the gethostbyname function should be used with the machine name of the PC. You can find the name of the partner PC in the registry under the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\Partners. Because Windows CE systems can have two partners, you first have to check which partner is active. Do this by reading the PCur value under the key. Then look under the P1 or P2 subkey and read the string value PName. Remember to change the string from a Unicode string to a character string before calling gethostbyname.Now I come to the end of my explanation of the PC-side ActiveSync. For the remainder of the book, I'll return to the Windows CE side of things. I'll start with a look at the different shells that Windows CE supports. The Explorer shell looks on the surface like the old Windows 95 shell, although the programming interface is much simpler. The Pocket PC shell, on the other hand, is completely unique.