Retrieving System Information
得到指定的设备系统信息使你的程序能够在下面几个方面交付内容或改变功能:
· 连接设备上使用的处理器,当应用程序上传一个包含指定处理器的文件的CAB文件到设备上时。
注意 这项技术最常用的环境是当你发布应用程序到早期版本的Pocket PC设备上,例如基于ARM处理器的Windows Mobile设备。
· 运行在连接设备上的操作系统版本,根据处理器类型使用相应文件进行更新。
· 连接设备的电源状态,经常用于在使用者进入区域前,警告他们的设备运行于低电量状态下。
· 连接设备的内存状态,用于检测数据是否可以下载,如果用户下载了未被授权的应用程序或者其他内存相关函数,或者判断你是否有足够的空间安装应用程序的更新。
这部分操作的演示界面见图5。

Figure 5. The Device Information tab of the RAPI demo program
RAPI类提供了四个方法来得到这些信息,GetDeviceSystemInfo (处理器类型), GetDeviceVersion (操作系统版本), GetDeviceSystemPowerStatus (电源状态) 和 GetDeviceMemoryStatus (内存).
BtnInfoRetrieve按钮的点击事件示范了这些方法。
[VC#.NET]
private void btnInfoRetrieve_Click(object sender, System.EventArgs e)
{
string info;
MEMORYSTATUS ms;
SYSTEM_INFO si;
SYSTEM_POWER_STATUS_EX sps;
OSVERSIONINFO vi;
// Retrieve the system information.
myrapi.GetDeviceSystemInfo(out si);
// Retrieve the device OS version number.
myrapi.GetDeviceVersion(out vi);
// Retrieve the device power status.
myrapi.GetDeviceSystemPowerStatus(out sps);
// Retrieve the device memory status.
myrapi.GetDeviceMemoryStatus(out ms);
// Format the retrieved information.
info = "The connected device has an ";
switch (si.wProcessorArchitecture)
{
case ProcessorArchitecture.Intel:
info += "Intel processor.\n";
break;
case ProcessorArchitecture.MIPS:
info += "MIPS processor.\n";
break;
case ProcessorArchitecture.ARM:
info += "ARM processor.\n";
break;
default:
info = "unknown processor type.\n";
break;
}
info += "OS version: " + vi.dwMajorVersion + "." +
vi.dwMinorVersion + "." +
vi.dwBuildNumber + "\n";
if (sps.ACLineStatus == 1)
{
info += "On AC power: YES\n";
}
else
{
info += "On AC power: NO \n";
}
info += "Battery level: " + sps.BatteryLifePercent + "%\n";
info += "Total memory: " + String.Format("{0:###,###,###}",
ms.dwTotalPhys) +
"\n";
// Display the results.
lblInfo.Text = info;
}
[VB.NET]
Private Sub btnInfoRetrieve_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnInfoRetrieve.Click
Dim info As String
Dim ms As New MEMORYSTATUS
Dim si As New SYSTEM_INFO
Dim sps As New SYSTEM_POWER_STATUS_EX
Dim vi As New OSVERSIONINFO
' Retrieve the system information.
myrapi.GetDeviceSystemInfo(si)
' Retrieve the device OS version number.
myrapi.GetDeviceVersion(vi)
' Retrieve the device power status.
myrapi.GetDeviceSystemPowerStatus(sps)
' Retrieve the device memory status.
myrapi.GetDeviceMemoryStatus(ms)
' Format the retrieved information.
info = "The connected device has an "
Select Case si.wProcessorArchitecture
Case ProcessorArchitecture.Intel
info += "Intel processor." & vbCrLf
Case ProcessorArchitecture.MIPS
info += "MIPS processor." & vbCrLf
Case ProcessorArchitecture.ARM
info += "ARM processor." & vbCrLf
Case Else
info = "unknown processor type." & vbCrLf
End Select
info += "OS version: " & vi.dwMajorVersion & "." & vi.dwMinorVersion
& "." & vi.dwBuildNumber & vbCrLf
info += "On AC power: " & IIf(sps.ACLineStatus = 1, "YES", "NO")
& vbCrLf
info += "Battery level: " & sps.BatteryLifePercent & "%" & vbCrLf
info += "Total memory: " & String.Format("{0:###,###,###}",
ms.dwTotalPhys) & vbCrLf
' Display the results.
lblInfo.Text = info
End Sub
到这里我们如果将桌面应用程序加入到你的移动解决方案和关于Remote API的介绍就要告以段落了。我建议你花一些时间来检验OpenNETCF.Desktop.Communication命名空间提供的其他的功能。记住,那才是所有的操作,OpenNETCF命名空间为你的应用程序提供了多种类的操作。
Back on the Road
又是一个新的月份了。春天已经来到了每个角落,我要带着我的滑水板和Pocket PC前往阳光充足的Florida。在我的下一篇文章里,我们将检验关于移动开发者更多的操作。