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:
<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
Please help: what am I doing wrong?
Thank you, Fabio