一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

桌面端的移动运算(二)

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

Working with the RAPI Class
为了简化RAPI类的操作,我将添加一个using声明到示例程序的C#版本,或添加一个Imports声明到VB.NET中,示例如下:
[VC#.NET]
using OpenNETCF.Desktop.Communication;
[VB.NET]
Imports OpenNETCF.Desktop.Communication
另外,我将添加一个单独的module-level变量,myrapi,用于保存一个RAPI类的实例。
[VC#.NET]
// Declare an instance of the RAPI object.
RAPI myrapi;
[VB.NET]
' Declare an instance of the RAPI object.
Dim WithEvents myrapi As New rapi
Connecting to the Device
当你的桌面程序使用RAPI类时,第一步是要与设备建立一个连接。
注意:在桌面程序中使用RAPI必须要有一个PC与设备之间的激活的ActiveSync连接。
在这篇文章包含的示例程序中,在Form_Load事件中将连接到设备。为了连接到设备,你使用RAPI类的Connect方法。正如下面代码所演示的,我紧接着检查了RAPI类的DevicePresent属性,来校验连接是否成功。
[VC#.NET]
try
// Connect to the device.
{
myrapi.Connect();
while (! myrapi.DevicePresent)
{
MessageBox.Show("Please connect your device to your PC using
ActiveSync and before clicking the OK button.",
"No Device Present");
myrapi.Connect();
}
}

catch (Exception ex)
{
MessageBox.Show("The following error occurred while attempting
to connect to"+ " your device - " + ex.Message,
"Connection Error");
Application.Exit();
}
[VB.NET]
Try
' Connect to the device.
myrapi.Connect()
Do While Not myrapi.DevicePresent

热门栏目