4
votes

I have written a very simple Inventory Tracking application for a Motorola MC3190 Mobile Device. I need to transfer data to and from the device and a Windows 7 PC.

I have scoured the internet for options on how to do this but so far nothing has worked. I am very new to developing Mobile applications and have limited knowledge of C#. (Just enough to develop a simple data capture app).

I have downloaded and installed the Windows Mobile Device Center, Windows Mobile 6 SDK and OpenNETCF Smart Device Framework to get access to RAPI. I know the Remote Device is connected properly through the Windows Mobile Device Center and VS2008 is able to deploy my solution to the device. I can also copy files back and forth manually via the Windows Mobile Device Center.

What I have tried so far is:

Add a OpenNetCF.Desktop.Communications Refernce

Used Code as follows:

        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();

        }

I get the error (Cannot Find PInvoke.dll in RAPI.dll) when creating a new RAPI Instance because it appears to be trying to use ActiveSync. I cannot load ActiveSync because I am running Windows 7.

I have tried adding the following code:

    [DllImport("rapi.dll")]
    static extern int CeRapiInit();

and then calling

        var rapi = CeRapiInit() == ERROR_SUCCESS;  <-- Return Value is -2147024770

        if (!rapi)
            return;

        try
        {
          .. Somestuff
        }
        finally
        {
            CeRapiUninit();
        }

It appears that RAPI cannot find the remote device. I have looked at some options for pget and pput functions but they also crap out on the CeRapiInit call. Perhaps I may not be able to use RAPI at all

Any help would be appreciated.

2

2 Answers

3
votes

If you are using Windows Mobile 6.5, I suggest you to use RAPI2, and the wrapper provided on codeplex here: https://rapi2.codeplex.com/

I used it in the past and it's perfect. Here you should have a look to the following methods:

CopyFileFromDevice
CopyFileToDevice

They can be used quickly like shown in the documentation:

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);
   }
}
0
votes

Error -2147024770 code means "Module no found", it does not mean there is no device found.

RAPI usage will not be the problem ActiveSync and WMDC are two terms for the same.

I am running a C/C++ app using AS/WMDC on my Win7 x64 PC: http://www.hjgode.de/wp/2012/03/28/mobile-development-autohide-windows-mobile-device-center-2/

I also started with OpenNetCF.Desktop.Communication but it behaved to bad and so I went over to C/C++.