Scan Class

Discussions about TWAIN & WIA scanning in GdPicture.NET using GdPictureImaging.
Post Reply
PQSIK
Posts: 50
Joined: Wed Oct 21, 2009 7:26 pm

Scan Class

Post by PQSIK » Mon Feb 28, 2011 2:41 am

Hi there,

I'm having a problem with scanning.

I thought I would have a class to setup twain properties, start the scan and return a list of images

Code: Select all

Public Class GDTwainSetup
    Private Profile As ScanProfile
    Private oGdPictureImaging As GdPictureImaging
    Private PageCounter As Integer
    Private ThisIntPtr As System.IntPtr


    Public Sub New(ByVal mProfile As ScanProfile, ByVal Handel As System.IntPtr)
        Profile = mProfile
        ThisIntPtr = Handel
    End Sub

Public Function RunScan() As List(Of Bitmap)

Dim lst As New List(Of Bitmap)


oGdPictureImaging = New GdPictureImaging()
oGdPictureImaging.SetLicenseNumber("")
oGdPictureImaging.TwainLogStart("c:\temp\gdtwain.log")

If oGdPictureImaging.TwainGetSourceCount(IntPtr.Zero) = 0 Then
            MessageBox.Show("No scanner found")
            Return Nothing
End If

Init

If oGdPictureImaging.TwainGetState() = TwainStatus.TWAIN_SOURCE_OPEN Then
Do
	ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(ThisIntPtr)
                If ImageID = 0 Then
                    oGdPictureImaging.TwainCloseSource()
                    Exit Do
                End If
                
                If (Profile.EnableDuplex And oGdPictureImaging.IsBlank(ImageID, CSng(Profile.SetBlankPageThreshold / 100))) Then
                    oGdPictureImaging.ReleaseGdPictureImage(ImageID)
                Else
                    ApplyImageFilters(ImageID, oGdPictureImaging)
                    lst.Add(oGdPictureImaging.GetBitmapFromGdPictureImage(ImageID))
                End If
                oGdPictureImaging.ReleaseGdPictureImage(ImageID)
            Loop While oGdPictureImaging.TwainGetState = TwainStatus.TWAIN_SOURCE_ENABLED
      
end if

End Function

Private Sub Init()
       Dim Status As Boolean = False
        If Profile.Source.Trim().Length > 0 Then
          Try
          oGdPictureImaging.TwainCloseSource()
          oGdPictureImaging.TwainCloseSourceManager(IntPtr.Zero)
          blnStaus = oGdPictureImaging.TwainOpenSource(IntPtr.Zero, Profile.Source) "Errors here"
            Catch
                Staus = oGdPictureImaging.TwainOpenDefaultSource(IntPtr.Zero)
            End Try
        Else
            oGdPictureImaging.TwainCloseSource()
            oGdPictureImaging.TwainCloseSourceManager(IntPtr.Zero)
            Staus = oGdPictureImaging.TwainOpenDefaultSource(IntPtr.Zero)
        End If
End Sub

The error is:
Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

I know I can change the Debug > exception > Managed Debugging Assistants and unchecked LoaderLock, I don't want to do that if when built it causes problem on user computer.

The demo's and posts I see run code in the form. Should this method work, do I need to have the code in the from and use its handle?

spec
Windows xp sp3
Visual studio 2008
gdPicture 7.4.0.1

Thanks

PQSIK
Posts: 50
Joined: Wed Oct 21, 2009 7:26 pm

Re: Scan Class

Post by PQSIK » Mon Feb 28, 2011 3:36 am

When I put

Code: Select all

MessageBox.Show(oGdPictureImaging.TwainGetSourceCount().ToString)
its scanned ok without the error.

the TwainGetSourceCount must be doing something.

I have

Code: Select all

If oGdPictureImaging.TwainGetSourceCount(Nothing) = 0 Then
in the code.

The messagebox must be doing something, not sure what yet.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scan Class

Post by Loïc » Mon Feb 28, 2011 10:04 am

Hi,

I can't reproduce the problem. Please attach a standalone project reproducing the issue. Or send it to https://www.gdpicture.com/support/getting-support-from-our-team

Kind regards,

Loïc

PQSIK
Posts: 50
Joined: Wed Oct 21, 2009 7:26 pm

Re: Scan Class

Post by PQSIK » Mon Feb 28, 2011 10:29 pm

Attached zipped project shows loaderlock

you have to check loaderlock exception in visual studio or it will run fine

thanks
pqsik

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scan Class

Post by Loïc » Tue Mar 01, 2011 10:06 am

Hi,

I successfully ran your project with latest release on WinXp, Vista & Seven.

BTW, I had to remove your project from your post since it was including license KEY.

I can suggest you to try to use latest version of GdPicture.NET.

Kind regards,

Loïc

PQSIK
Posts: 50
Joined: Wed Oct 21, 2009 7:26 pm

Re: Scan Class

Post by PQSIK » Sat Mar 05, 2011 7:23 pm

thanks for your reply,

Did you check loaderlock exception?

What version of Visual Studio did you test it with?

pqsik

jrichmeier
Posts: 1
Joined: Fri Jan 20, 2012 5:07 pm

Re: Scan Class

Post by jrichmeier » Fri Jan 20, 2012 5:21 pm

I am currently evaluating the product and have run into the same issue.

I have found that the issue exists in the sample application that is provided as part of the install. Please see the attached screenshot for the line of code that is throwing the error. I have also noticed that this error is thrown only when the "Hide UI" checkbox is unchecked. If I have this checkbox unchecked, the error will occur every time. I am not sure if it makes any difference or not, but I clicked the "Demo 5" button. It is also important to note that this error will only be thrown when the application is being run in Debug mode.

Other than getting purchase approval, I am ready to buy a license or two but wanted to see about this issue first. I am not sure if it is really as bad as it sounds but it does make it sound nasty and as though problems might occur.

Please advise.
Attachments
SceenShot.JPG

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Scan Class

Post by Loïc » Fri Jan 20, 2012 5:37 pm

Hi,

This problem occurs only in debugging mode through Visual Studio. You have simply to deactivate the exception as explained in this topic:
Menu Debug > exception > Managed Debugging Assistants and unchecked LoaderLock
Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest