我为摩托罗拉 MC3190 移动设备编写了一个非常简单的库存跟踪应用程序。
我需要在设备和 Windows 7 PC 之间传输数据。
我已经在互联网上搜索有关如何执行此操作的选项,但到目前为止没有任何效果。
我对开发移动应用程序非常陌生,并且对 C# 的了解有限。 (足以开发一个简单的数据捕获应用程序)。
我已经下载并安装了 Windows Mobile Device Center、Windows Mobile 6 SDK 和 OpenNETCF Smart Device Framework 以访问 RAPI。我知道远程设备已通过 Windows Mobile 设备中心正确连接,并且 VS2008 能够将我的解决方案部署到设备上。我还可以通过 Windows Mobile 设备中心手动来回复制文件。
到目前为止我尝试过的是:
添加 OpenNetCF.Desktop.Communications 引用
使用的代码如下:
using (RAPI rapi = new RAPI()) <--- Error Occurs (Cannot Find PInvoke.dll in RAPI.dll)
{
rapi.Connect(true);
rapi.CopyFileToDevice(remote_file, local_file);
rapi.Disconnect();
}
我在创建新的 RAPI 实例时收到错误(无法在 RAPI.dll 中找到 PInvoke.dll),因为它似乎在尝试使用 ActiveSync。我无法加载 ActiveSync,因为我运行的是 Windows 7。
我尝试添加以下代码:
[DllImport("rapi.dll")]
static extern int CeRapiInit();
然后打电话
var rapi = CeRapiInit() == ERROR_SUCCESS; <-- Return Value is -2147024770
if (!rapi)
return;
try
{
.. Somestuff
}
finally
{
CeRapiUninit();
}
RAPI 似乎找不到远程设备。
我已经查看了 pget 和 pput 函数的一些选项,但它们也在 CeRapiInit 调用中失败了。也许我可能根本无法使用 RAPI
任何帮助,将不胜感激。
最佳答案
如果您使用的是 Windows Mobile 6.5,我建议您使用 RAPI2,以及此处提供的 codeplex 包装器:https://rapi2.codeplex.com/
我过去用过它,它是完美的。在这里你应该看看以下方法:
CopyFileFromDevice
CopyFileToDevice
它们可以像文档中显示的那样快速使用:
using (RemoteDeviceManager r = new RemoteDeviceManager())
{
using (RemoteDevice dev = r.Devices.FirstConnectedDevice)
{
if (dev == null)
return;
// Device information
Console.WriteLine(dev.Name + ":" + dev.Platform);
Console.WriteLine("Remaining power: {0}%", dev.PowerStatus.BatteryLifePercent);
// Manipulate local and device files & directories
string myDocs = dev.GetFolderPath(SpecialFolder.MyDocuments);
string deviceFile = myDocs + @"\Test.txt";
string localFile = System.IO.Path.GetTempFileName();
System.IO.File.WriteAllText(localFile, "Testing. 1. 2. 3.");
RemoteFile.CopyFileToDevice(dev, localFile, deviceFile, true);
RemoteFile.CopyFileFromDevice(dev, myDocs + @"\Test.txt", localFile, true);
}
}
关于windows-mobile-6.5 - 使用 Windows Mobile 设备/Windows 7 复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23277397/