|
"Application.AddMessageFilter() " doesn't work in ASP.net
this fn is only supported by windows form
wat is the alternative of this function for web page
sssssss
|
|
|
|
|
I've tried to scan with my scanner locked for transport (switch button on the device) and in this case
<br />
TwainCommand cmd = tw.PassMessage(ref m);<br />
sets cmd to null and program falls into infinite loop.
The solution is to capture null TwainCommand and close cource:
<br />
EndingScan();<br />
tw.CloseSrc();<br />
Bartosz Węgielewski
|
|
|
|
|
The message-handling doesn't seem to work on Windows 2000. The messages that is supposed to be handled by IMessageFilter.PreFilterMessage newer turns up, and it is not possible to scan anything.
At least not on my HP Scanjet 5530.
Is this a generel Win2000 problem, or is it related to my scanner?
On Xp everything works fine.
Regards
Jørn Esbensen
|
|
|
|
|
Try to update your TWAIN_32.dll
|
|
|
|
|
good day! i'm new with scanning in .net
using your library, how can i get multiple images using the multi scanning capability of the scanner?
|
|
|
|
|
Search for
TwCapability cap = new TwCapability( TwCap.XferCount, 1 );
change it to
TwCapability cap = new TwCapability( TwCap.XferCount, -1 );
This also works for duplex scanning. You must stop the scanning manually however. In my case, this is done through the twain dialog.
Good luck!
|
|
|
|
|
How can I set a particular resolution(200dpi,500dpi,etc)?
I'm trying to change these lines:
TwCapability capResx = new TwCapability(TwCap.IXResolution, 72, TwType.Fix32);
TwCapability capResy = new TwCapability(TwCap.IYResolution, 72, TwType.Fix32);
but I don't founded documentation about the parameters TwCap cap, short sval and TwType twtype.
Can you comment its?
Thanks you very much,
Marcel
|
|
|
|
|
'Put this in Acquire
Public Sub Acquire(Optional ByVal XResolution As Integer = 300, Optional ByVal YResolution As Integer = 300)
Dim rc As TwRC
CloseSrc()
If Equals(appid.Id, IntPtr.Zero) = True Then
Init(hwnd)
If Equals(appid.Id, IntPtr.Zero) = True Then
Return
End If
End If
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds)
If (rc <> TwRC.Success) Then
Return
End If
Dim capUnit As TwCapability = New TwCapability(TwCap.IUnits, 0, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capUnit)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
'Set Resolution
Dim capX As TwCapability = New TwCapability(TwCap.XResolution, XResolution, TwType.Fix32)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capX)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
Dim capY As TwCapability = New TwCapability(TwCap.YResolution, YResolution, TwType.Fix32)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capY)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
Dim cap As TwCapability = New TwCapability(TwCap.XferCount, 1, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
Dim guif As TwUserInterface = New TwUserInterface
guif.ShowUI = 0
guif.ModalUI = 0
guif.ParentHand = hwnd
rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
End Sub
'Now Change this
Friend Enum TwCap As Short
XferCount = &H1
ICompression = &H100
IPixelType = &H101
IUnits = &H102
IXferMech = &H103
BITDEPTH = &H112B
ICAP_IMAGEFILEFORMAT = &H110C
XResolution = &H1118
YResolution = &H1119
ImageWidth = &H1116
ImageLength = &H1117
End Enum
'And this
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwCapability
Public Cap As Short
Public ConType As Short
Public Handle As IntPtr
Public Sub TwCapability(ByVal capIn As TwCap)
Cap = CType(capIn, Short)
ConType = -1
End Sub
Public Sub New(ByVal capIn As TwCap, ByVal sval As Short, ByVal TWType As TwType)
Cap = CType(capIn, Short)
ConType = CType(TwOn.One, Short)
Handle = Twain.GlobalAlloc(&H42, 6)
Dim pv As IntPtr = Twain.GlobalLock(Handle)
Marshal.WriteInt16(pv, 0, CType(TWType, Short))
Marshal.WriteInt32(pv, 2, CType(sval, Integer))
Twain.GlobalUnlock(Handle)
End Sub
Public Sub Dispose()
If Not Equals(Handle, IntPtr.Zero) Then
Twain.GlobalFree(Handle)
End If
End Sub
Protected Overrides Sub Finalize()
If Not Equals(Handle, IntPtr.Zero) Then
Twain.GlobalFree(Handle)
End If
End Sub
End Class
'It should work! This code is working in my computer.
'Sorry I just have VB.NET version. May be you can convert it to C# by your own.
MCChin
-- modified at 0:09 Thursday 14th September, 2006
|
|
|
|
|
I used this code in my program. 'rc' allways returns TwRC.Success for every capability, but real image resolution doesn't change. Why can it be?
|
|
|
|
|
If I run the app available in the download, I can scan an image fine the first time. But, if I close the app and try to re-launch it, it just sits there as if it was in an infinite loop of sorts. When tracing, it never emerged from the tw.Init() method call. Within the Init call, it seems to get hung up on the call to DSMparent(...).
I'm running this using VS2005 on WinXP Pro SP2.
Have any of you encountered this issue before?
Thanks
|
|
|
|
|
Hi,
I'm trying to configure the scan area but it's not working. This is what I'm using:
I added these two structs:
<br />
[StructLayout(LayoutKind.Sequential, Pack = 2)]<br />
internal struct TwFrame {<br />
public TwFix32 Left;<br />
public TwFix32 Top;<br />
public TwFix32 Right;<br />
public TwFix32 Bottom;<br />
}<br />
<br />
[StructLayout(LayoutKind.Sequential, Pack = 2)]<br />
internal class TwImageLayout {<br />
public TwFrame Frame;<br />
public int DocumentNumber;<br />
public int PageNumber;<br />
public int FrameNumber;<br />
}<br />
Then I created this imported function:
<br />
[DllImport("twain_32.dll", EntryPoint = "#1")]<br />
private static extern TwRC DSilayout([In, Out] TwIdentity origin, [In] TwIdentity dest, TwDG dg, TwDAT dat, TwMSG msg, [In, Out] TwImageLayout imglo);<br />
And finally I try to set the scan area using a call like this:
<br />
TwFrame fr = new TwFrame();<br />
TwFix32 fix32 = new TwFix32();<br />
fix32.FromFloat((float)left);<br />
fr.Left = fix32;<br />
fix32.FromFloat((float)top);<br />
fr.Top = fix32;<br />
fix32.FromFloat((float)right);<br />
fr.Right = fix32;<br />
fix32.FromFloat((float)bottom);<br />
fr.Bottom = fix32;<br />
TwImageLayout layout = new TwImageLayout();<br />
layout.Frame = fr;<br />
layout.DocumentNumber = 0;<br />
layout.PageNumber = 0;<br />
layout.FrameNumber = 0;<br />
TwRC rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Set, layout);<br />
rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, layout);<br />
This call returns TwRC.Succes, but if I call DSilayout with TwMSG.Get, I can see that the frame is not set. And ofcourse when I acquire() I get an image of the whole scan bed.
Can anyone helpme with this matter?
Thanks in advance.
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal struct TwFrame {
public int Left;
public int Top;
public int Right;
public int Bottom;
}
//set the scan area using a call like this
TwImageLayout layout = new TwImageLayout();
//Get the default layout
TwRC rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, Layout);
Layout.Frame.Top = 0; //Set the top margin
Layout.Frame.Left = 0; //Set left margin
Layout.Frame.Right = 0; //Set right margin
Layout.Frame.Bottom = 0; //Set bottom margin
Layout.FrameNumber = 1;
Layout.PageNumber = 1;
Layout.DocumentNumber = 1;
rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Set, layout);
TwStatus s = new TwStatus();
rc = DSstatus(appid, srcds, TwDG.Control, TwDAT.Status, TwMSG.Get, s);
if( rc != TwRC.Success )
{
CloseSrc();
return false;
}
|
|
|
|
|
'VB.NET Code. Please convert by your self to C#. This work in my pc and give better performance.
'Set Layout
Dim Layout As TwImageLayout = New TwImageLayout
rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, Layout)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
If TopMargin > 0 Then
Layout.Frame.Top.FromFloat(CSng(TopMargin))
End If
If LeftMargin > 0 Then
Layout.Frame.Left.FromFloat(CSng(LeftMargin))
End If
If RightMargin > 0 Then
Layout.Frame.Right.FromFloat(CSng(RightMargin))
End If
If BottomMargin > 0 Then
Layout.Frame.Bottom.FromFloat(CSng(BottomMargin))
End If
Layout.FrameNumber = 1
Layout.PageNumber = 1
Layout.DocumentNumber = 1
rc = Me.DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Set, Layout)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwFrame
Public Left As TwFix32
Public Top As TwFix32
Public Right As TwFix32
Public Bottom As TwFix32
End Structure
|
|
|
|
|
Hello,
when I execute this code, in the SET it returns FAILURE. Why?. I have to add some Capability.
Thank you for your help
|
|
|
|
|
Public Sub Acquire()
Dim rc As TwRC
CloseSrc()
If Equals(appid.Id, IntPtr.Zero) = True Then
Init(hwnd)
If Equals(appid.Id, IntPtr.Zero) = True Then
Return
End If
End If
rc = DSMident(appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds)
If (rc <> TwRC.Success) Then
Return
End If
'Set Unit to Pixels
Dim Pixels As TwUnit = TwUnit.twPIXELS
Dim capUnit As TwCapability = New TwCapability(TwCap.IUnits, Pixels, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capUnit)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
Dim xcap As TwCapability = New TwCapability(TwCap.XScaling, XScale, TwType.Fix32)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, xcap)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
xcap = New TwCapability(TwCap.YScaling, YScale, TwType.Fix32)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, xcap)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
Dim ps As TwCapability = New TwCapability(TwCap.SupportedSizes, PaperSize, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, ps)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
'Set Layout
Dim Layout As TwImageLayout = New TwImageLayout
rc = DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Get, Layout)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
If TopMargin > 0 Then
Layout.Frame.Top.FromFloat(CSng(TopMargin))
End If
If LeftMargin > 0 Then
Layout.Frame.Left.FromFloat(CSng(LeftMargin))
End If
If RightMargin > 0 Then
Layout.Frame.Right.FromFloat(CSng(RightMargin))
End If
If BottomMargin > 0 Then
Layout.Frame.Bottom.FromFloat(CSng(BottomMargin))
End If
Layout.FrameNumber = 1
Layout.PageNumber = 1
Layout.DocumentNumber = 1
rc = Me.DSilayout(appid, srcds, TwDG.Image, TwDAT.ImageLayout, TwMSG.Set, Layout)
If rc <> TwRC.Success Then
CloseSrc()
Return
End If
'Scan Colour
Dim Ccap As TwCapability = New TwCapability(TwCap.IPixelType, SColor, TwType.UInt16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, Ccap)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
Dim cap As TwCapability = New TwCapability(TwCap.XferCount, 1, TwType.Int16)
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
Dim guif As TwUserInterface = New TwUserInterface
guif.ShowUI = 1
guif.ModalUI = 1
guif.ParentHand = hwnd
rc = DSuserif(appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif)
If (rc <> TwRC.Success) Then
CloseSrc()
Return
End If
End Sub
'Full code here. Just replace the original Acquire in TwainLib.vb from NETMaster. It should be work.
'Remember to change this also in the TwainDefs.vb.
<StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)> Friend Class TwIdentity
Public Id As IntPtr
Public Version As TwVersion
Public ProtocolMajor As Short
Public ProtocolMinor As Short
Public SupportedGroups As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public Manufacturer As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public ProductFamily As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public ProductName As String
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2, CharSet:=CharSet.Ansi)> Friend Structure TwVersion
Public MajorNum As Short
Public MinorNum As Short
Public Language As Short
Public Country As Short
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=34)> Public Info As String
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwUserInterface
Public ShowUI As Short
Public ModalUI As Short
Public ParentHand As IntPtr
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwStatus
Public ConditionCode As Short
Public Reserved As Short
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwEvent
Public EventPtr As IntPtr
Public Message As Short
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwImageInfo
Public XResolution As Int32
Public YResolution As Int32
Public ImageWidth As Int32
Public ImageLength As Int32
Public SamplesPerPixel As Int16
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public BitsPerSample() As Short
Public BitsPerPixel As Int16
Public Planar As Boolean
Public PixelType As Int16
Public Compression As Short
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwPendingXfers
Public Count As Short
Public EOJ As Integer
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwFix32
Public Whole As System.Int16
Public Frac As System.UInt32
Public Function ToFloat() As Single
Dim frac_sng As Single
frac_sng = System.Convert.ToSingle(Frac)
Return CType(Whole + (CType(frac_sng, Single) / 65536.0F), Single)
End Function
Public Sub FromFloat(ByVal f As Single)
Dim i As Int32 = CType(((f * 65536.0F) + 0.5F), Int32)
Whole = System.Convert.ToInt16(i / 2 ^ 16)
Frac = System.Convert.ToUInt32((i Or &HFFFF))
End Sub
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Structure TwFrame
Public Left As TwFix32
Public Top As TwFix32
Public Right As TwFix32
Public Bottom As TwFix32
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwImageLayout
Public Frame As TwFrame
Public DocumentNumber As Integer
Public PageNumber As Integer
Public FrameNumber As Integer
End Class
<StructLayout(LayoutKind.Sequential, Pack:=2)> Friend Class TwCapability
Public Cap As Short
Public ConType As Short
Public Handle As IntPtr
Public Sub TwCapability(ByVal capIn As TwCap)
Cap = CType(capIn, Short)
ConType = -1
End Sub
Public Sub New(ByVal capIn As TwCap, ByVal sval As Short, ByVal TWType As TwType)
Cap = CType(capIn, Short)
ConType = CType(TwOn.One, Short)
Handle = Twain.GlobalAlloc(&H42, 6)
Dim pv As IntPtr = Twain.GlobalLock(Handle)
Marshal.WriteInt16(pv, 0, CType(TWType, Short))
Marshal.WriteInt32(pv, 2, CType(sval, Short))
Twain.GlobalUnlock(Handle)
End Sub
Public Sub Dispose()
If Not Equals(Handle, IntPtr.Zero) Then
Twain.GlobalFree(Handle)
End If
End Sub
Protected Overrides Sub Finalize()
If Not Equals(Handle, IntPtr.Zero) Then
Twain.GlobalFree(Handle)
End If
End Sub
End Class
|
|
|
|
|
I have solution in .Net with 2 projects . each projects contains one class and one interface each.. The interface contains name of function in class.
I have 3rd project with one interface . i want call all the 2 other interface in those 2 project in this interface and call that interface in client..
Please help me to solve this issue..
Joe
|
|
|
|
|
when I used it in the mainform, i mean in the parent windows,
it work great.
but i need to used it in the child window,
when it run the "select" or "acquire" nothing happen
it seem the child window can't catch the message.
very urgent.
please help.
|
|
|
|
|
set IsMdiContainer to true if you are using dotnet in properties window
|
|
|
|
|
Hi man, this is not working on VS 2005.
when i run it, nothing happens... any comments ??
thanks
ziad
|
|
|
|
|
OK , i found it, it is because of the "LoaderLock managed Debuging Assistent". MDAs only exsist in VS2005.
if anyone had this proplem, just go to Debug/Exceptions then + Managed Debuging Assistants then find and uncheck LoaderLock checkbox.
ziad
ziad
|
|
|
|
|
Hi,
I am new on twain. I have download the demo and also source files of this application. After I run this application, I have selected "Select Source". But nothing is happened. I have debugged the code. And in this part :
public void Init( IntPtr hwndp )<br />
{<br />
Finish();<br />
TwRC rc = DSMparent( appid, IntPtr.Zero, TwDG.Control, TwDAT.Parent, TwMSG.OpenDSM, ref hwndp );<br />
...<br />
}
rc returned as Failure. Where is the wrong? I have checked that in C:/WINDOWS directory, there are;
twunk_16.exe
twunk_32.exe
twain_32.dll
twain.dll
files. Is there any other needs such as registry any dll?
Thanks.
|
|
|
|
|
I've tried setting:
In the "Acquire" method in TwainLib.cs change:
TwCapability cap = new TwCapability( TwCap.XferCount, 1 );
to
TwCapability cap = new TwCapability( TwCap.XferCount, -1 );
However, it stops after scanning one image and I have to go through clicking acquire scan for the next image.
Can someone please send me a zip file of their project with scanning multi pages?
Thanks.
|
|
|
|
|
Hi asp-123,
Have anyone send you their zip file ?
Cause I have the same issue here, I also try below code in "Acquire" method
TwCapability cap = new TwCapability( TwCap.XferCount, 2 );
but it still did not work.
If you guys have sample application that you can send me, please send it to
tjendarta@gmail.com
I spent too much time and I really need this
Thank you
|
|
|
|
|
To scan multiple page you must execute the complete twain cycle many times over.
I believe that CAP_XFERCOUNT capability work on ADF scanner.
|
|
|
|
|
You set the Xfercount to -1 for multiple scans and 1 for a single scan.
Alan MacFadyen
|
|
|
|
|