locked
Calling twain32.dll from VB.Net Problems with Nikon Coolscan IV

    General discussion

  • Hallo!

    I am using code from http://www.codeproject.com/KB/dotnet/twaindotnet.aspx and it used to work quite well. Recently I got a Nikon Coolscan IV Scanner (about nine years old) and the application crashes when a picture is getting scanned. The Code is:

    Public Function TransferPictures() As ArrayList

          Dim pics As New ArrayList
          If (srcds.Id = IntPtr.Zero) Then
            Return pics
          End If
          Dim rc As TwRC
          Dim hbitmap As IntPtr = IntPtr.Zero
          Dim pxfr As New TwPendingXfers()

          Do
            Try
              pxfr.Count = 0
              hbitmap = IntPtr.Zero

              Dim iinf As New TwImageInfo()
              rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf)
              If (rc <> TwRC.Success) Then

                CloseSrc()
                Return pics

              End If
              'Here it crashes with an Access Violation
              rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, hbitmap)
              If (rc <> TwRC.XferDone) Then

                CloseSrc()
                Return pics
              End If

              rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr)
              If (rc <> TwRC.Success) Then

                CloseSrc()
                Return pics
              End If

              pics.Add(hbitmap)
            Catch ex As Exception
              MsgBox(ex.Message)
              CloseSrc()
              Return pics
            End Try
          Loop While pxfr.Count <> 0


          rc = DSpxfer(appid, srcds, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr)
          Return pics

        End Function


    Regards Hans
    Monday, May 30, 2011 9:25 AM