Faulting module rapi.dll

Dec 19, 2011 at 9:09 AM

Hi,

I am using the OpenNETCF.Desktop.Communication.DLL (version 2.9.4262.14435) to read a file from a Motorola MT2070 scanner.

I have written an application in vb.NET (Framework 4.0) that checks every 5 seconds if a file is available on the scanner.

If a file is available it is copied from the scanner to a local folder on the pc for further processing.

 The program runs fine for most of the time, but occasionally i get an error like the one below, causing the program to close.

This problem occurs both with ActiveSync on Windows XP or with Windows Mobile Device Center on Windows 7.

 System.Runtime.InteropServices.COMException (0x80070006):
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at OpenNETCF.Desktop.Communication.RAPI.Connect(Boolean WaitForInit, Int32 TimeoutSeconds)
at OpenNETCF.Desktop.Communication.RAPI.Connect()
at Scanner_Interface.FrmMain.CheckDevice()
at Scanner_Interface.FrmMain.TimerClock_Tick(Object sender, EventArgs e)
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

 

Another issue I have is that the program sometimes freezes on the CeGetFileAttributes function in routine DeviceFileExists.

After 5 to 10 minutes the program continues again, but in the meantime the endusers have already restarted the program (with Task Manager).

After restarting the program everything works fine.

public bool DeviceFileExists(string RemoteFileName)
{
// check for connection
CheckConnection();

uint attr = CeGetFileAttributes( RemoteFileName );

if ( attr == 0xffffffff )
return false;

return true;
}

Does anyone recognize these issues ?

Any help is welcome…

 

Dec 19, 2011 at 9:28 AM

Below is the code i use to read a file from the scanner.

This routine is executed every 5 seconds.

    Private Sub ScanDevice()
        Dim oRAPI As New RAPI
        Try

            'Set remote file
            Dim RemoteFile As String = "\Application\MCL\Projects\Default\AA.dat"

            'Set local file
            Dim Filename As String = "C:\Temp\" & Format(DateTime.Now, "yyyyMMddhhmmss") & ".txt"

            'Check device present
            If Not oRAPI.DevicePresent Then Return

            'Open connection
            oRAPI.Connect()

            'Check device connected
            If Not oRAPI.Connected Then Return

            'Check remote file
            If oRAPI.DeviceFileExists(RemoteFile) Then

                'Get file size to check if the file is locked
                Try
                    oRAPI.GetDeviceFileSize(RemoteFile)
                Catch ex As Exception
                    Return
                End Try

                'Copy remote file
                oRAPI.CopyFileFromDevice(LocalFile, RemoteFile, True)

                'Delete remote file
                oRAPI.DeleteDeviceFile(RemoteFile)

            End If

        Catch ex As RAPIException

        Finally

            'Disconnect from device
            oRAPI.Disconnect()

            'Dispose object
            oRAPI.Dispose()

        End Try
    End Sub