【问题标题】:Copy Files with Windows Mobile Device/Windows 7使用 Windows Mobile 设备/Windows 7 复制文件
【发布时间】:2014-06-10 05:45:33
【问题描述】:

我为摩托罗拉 MC3190 移动设备编写了一个非常简单的库存跟踪应用程序。 我需要在设备和 Windows 7 PC 之间传输数据。

我已经在互联网上搜索了有关如何执行此操作的选项,但到目前为止没有任何效果。 我对开发移动应用程序非常陌生,并且对 C# 的了解有限。 (足以开发一个简单的数据捕获应用程序)。

我已经下载并安装了 Windows Mobile 设备中心、Windows Mobile 6 SDK 和 OpenNETCF 智能设备框架来访问 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 rapi


    【解决方案1】:

    如果您使用的是 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);
       }
    }
    

    【讨论】:

      【解决方案2】:

      错误-2147024770代码表示“未找到模块”,并不表示未找到设备。

      RAPI 使用不会成为问题 ActiveSync 和 WMDC 是同一个术语。

      我正在我的 Win7 x64 PC 上使用 AS/WMDC 运行 C/C++ 应用程序:http://www.hjgode.de/wp/2012/03/28/mobile-development-autohide-windows-mobile-device-center-2/

      我也是从 OpenNetCF.Desktop.Communication 开始的,但它的表现很糟糕,所以我转而使用 C/C++。

      【讨论】:

        猜你喜欢
        • 2013-11-12
        • 1970-01-01
        • 2010-09-21
        • 2010-10-02
        • 1970-01-01
        • 2012-08-01
        • 2012-02-02
        • 2011-02-19
        • 2013-02-08
        相关资源
        最近更新 更多