The TWAIN Forum

www.twainforum.org
It is currently Fri May 24, 2013 10:38 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Sep 21, 2011 7:08 am 
Offline

Joined: Fri Jun 08, 2007 3:25 am
Posts: 2
Hi all!
I'm having problem trying the buffered memory image transfer.

I'm working with VB.NET, and I'm currently able to manage sources, retrieve parameters, set capabilities, scan and retrieve image in native mode.

Now, the memory transfer issue:
when the sources notifies TransferReady, I can retrieve the twImageInfo, then correcly setup Tw_SetupMemXFer to retrieve buffer size, then allocate the buffer as needed. When I call the ImageMemXfer/Get, it fails with BadValue status.

Twain specs tell that this status is due to an incorrect buffer size.

This is how I defined the ImageMemXfer class:

Code:
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class Tw_ImageMemXfer
        Public Compression As UInt16
        Public BytesPerRow As UInt32
        Public Columns As UInt32
        Public Rows As UInt32
        Public XOffset As UInt32
        Public YOffset As UInt32
        Public BytesWritten As UInt32
        Public Memory As Tw_Memory

        Public Sub New(ByVal tws As DataStructures.Tw_SetupMemXFer)
                Me.Compression = UInt16.MaxValue
                Me.BytesPerRow = UInt32.MaxValue
                Me.Columns = UInt32.MaxValue
                Me.Rows = UInt32.MaxValue
                Me.XOffset = UInt32.MaxValue
                Me.YOffset = UInt32.MaxValue
                Me.BytesWritten = UInt32.MaxValue

                Dim lHBuffer As IntPtr = IntPtr.Zero
                Dim lBuffer As IntPtr = IntPtr.Zero

                lHBuffer = DllImports.kernel32.GlobalAlloc(&H42, tws.Preferred)
                lBuffer = DllImports.kernel32.GlobalLock(lHBuffer)

                Me.Memory = New Tw_Memory
                Me.Memory.Flags = Enumerations.TW_MEMORY_FLAGS.TWMF_APPOWNS Or Enumerations.TW_MEMORY_FLAGS.TWMF_POINTER
                Me.Memory.Lenght = tws.Preferred
                Me.Memory.TheMem = lBuffer
        End Sub

End Class


Please help: what am I doing wrong?

Thank you, Fabio


Top
 Profile  
 
PostPosted: Tue Nov 15, 2011 1:56 pm 
Offline

Joined: Tue Jul 27, 2010 10:39 am
Posts: 30
Location: Ottawa, ON
Me.Memory.Lenght = tws.Preferred <-- spelled Length wrong


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group