mirror of
https://github.com/soukoku/ntwain.git
synced 2025-07-15 13:16:14 +08:00
More update for internal loop handling.
This commit is contained in:
parent
d8512f7706
commit
3ae070e3a3
@ -12,8 +12,8 @@ namespace NTwain
|
|||||||
class _NTwainVersionInfo
|
class _NTwainVersionInfo
|
||||||
{
|
{
|
||||||
// keep this same in majors releases
|
// keep this same in majors releases
|
||||||
public const string Release = "0.10.0.0";
|
public const string Release = "0.11.0.0";
|
||||||
// change this for each nuget release
|
// change this for each nuget release
|
||||||
public const string Build = "0.10.2";
|
public const string Build = "0.11.0";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,8 +32,6 @@ namespace NTwain
|
|||||||
((ITwainStateInternal)this).ChangeState(1, false);
|
((ITwainStateInternal)this).ChangeState(1, false);
|
||||||
EnforceState = true;
|
EnforceState = true;
|
||||||
|
|
||||||
Debug.WriteLine("current thread id =" + Thread.CurrentThread.ManagedThreadId);
|
|
||||||
|
|
||||||
MessageLoop.Instance.EnsureStarted();
|
MessageLoop.Instance.EnsureStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,8 +296,6 @@ namespace NTwain
|
|||||||
rc = DGControl.Identity.CloseDS();
|
rc = DGControl.Identity.CloseDS();
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
MessageLoop.Instance.RemoveHook(HandleWndProcMessage);
|
|
||||||
_callbackObj = null;
|
|
||||||
SupportedCaps = null;
|
SupportedCaps = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -385,6 +381,14 @@ namespace NTwain
|
|||||||
rc = DGControl.UserInterface.DisableDS(_twui);
|
rc = DGControl.UserInterface.DisableDS(_twui);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
|
if (_callbackObj == null)
|
||||||
|
{
|
||||||
|
MessageLoop.Instance.RemoveHook(HandleWndProcMessage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_callbackObj = null;
|
||||||
|
}
|
||||||
OnSourceDisabled();
|
OnSourceDisabled();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -418,26 +422,29 @@ namespace NTwain
|
|||||||
// success, the return status from DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER may
|
// success, the return status from DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER may
|
||||||
// be ignored.
|
// be ignored.
|
||||||
|
|
||||||
if (targetState < 7)
|
MessageLoop.Instance.Invoke(() =>
|
||||||
{
|
{
|
||||||
DGControl.PendingXfers.EndXfer(new TWPendingXfers());
|
if (targetState < 7)
|
||||||
}
|
{
|
||||||
if (targetState < 6)
|
DGControl.PendingXfers.EndXfer(new TWPendingXfers());
|
||||||
{
|
}
|
||||||
DGControl.PendingXfers.Reset(new TWPendingXfers());
|
if (targetState < 6)
|
||||||
}
|
{
|
||||||
if (targetState < 5)
|
DGControl.PendingXfers.Reset(new TWPendingXfers());
|
||||||
{
|
}
|
||||||
DisableSource();
|
if (targetState < 5)
|
||||||
}
|
{
|
||||||
if (targetState < 4)
|
DisableSource();
|
||||||
{
|
}
|
||||||
CloseSource();
|
if (targetState < 4)
|
||||||
}
|
{
|
||||||
if (targetState < 3)
|
CloseSource();
|
||||||
{
|
}
|
||||||
CloseManager();
|
if (targetState < 3)
|
||||||
}
|
{
|
||||||
|
CloseManager();
|
||||||
|
}
|
||||||
|
});
|
||||||
EnforceState = origFlag;
|
EnforceState = origFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,12 +608,10 @@ namespace NTwain
|
|||||||
IntPtr HandleWndProcMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
IntPtr HandleWndProcMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||||
{
|
{
|
||||||
// this handles the message from a typical WndProc message loop and check if it's from the TWAIN source.
|
// this handles the message from a typical WndProc message loop and check if it's from the TWAIN source.
|
||||||
|
if (State >= 5)
|
||||||
var winmsg = new MESSAGE(hwnd, msg, wParam, lParam);
|
|
||||||
|
|
||||||
if (State >= 4) // technically we should only handle on state >= 5 but there might be missed msgs if we wait until state changes after enabling ds
|
|
||||||
{
|
{
|
||||||
// transform it into a pointer for twain
|
// transform it into a pointer for twain
|
||||||
|
var winmsg = new MESSAGE(hwnd, msg, wParam, lParam);
|
||||||
IntPtr msgPtr = IntPtr.Zero;
|
IntPtr msgPtr = IntPtr.Zero;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -614,7 +619,7 @@ namespace NTwain
|
|||||||
msgPtr = Marshal.AllocHGlobal(Marshal.SizeOf(winmsg));
|
msgPtr = Marshal.AllocHGlobal(Marshal.SizeOf(winmsg));
|
||||||
Marshal.StructureToPtr(winmsg, msgPtr, false);
|
Marshal.StructureToPtr(winmsg, msgPtr, false);
|
||||||
|
|
||||||
TWEvent evt = new TWEvent();
|
var evt = new TWEvent();
|
||||||
evt.pEvent = msgPtr;
|
evt.pEvent = msgPtr;
|
||||||
if (handled = (DGControl.Event.ProcessEvent(evt) == ReturnCode.DSEvent))
|
if (handled = (DGControl.Event.ProcessEvent(evt) == ReturnCode.DSEvent))
|
||||||
{
|
{
|
||||||
|
@ -4,13 +4,13 @@ TWAIN Application-Side Library
|
|||||||
Info
|
Info
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
This is a dotnet library created to work with [TWAIN](http://twain.org/) interface.
|
This is a dotnet library created to work with [TWAIN](http://twain.org/) interface.
|
||||||
This project follows these general goals:
|
This project has these features:
|
||||||
|
|
||||||
* Targets latest TWAIN version (2.3 at the moment)
|
* Targets latest TWAIN version (2.3 at the moment)
|
||||||
* Supports all the TWAIN functions in the spec
|
* Supports all the TWAIN functions in the spec
|
||||||
* Eventally work on platforms other than Windows (I can dream)
|
* Hosts internal message loop so no need to hook into application UI thread
|
||||||
|
|
||||||
The solution contains sample projects in winforms, wpf, and even (gasp!) console.
|
The solution contains tester projects in winform, wpf, and even (gasp!) console.
|
||||||
A nuget package is also [available here](https://www.nuget.org/packages/ntwain)
|
A nuget package is also [available here](https://www.nuget.org/packages/ntwain)
|
||||||
|
|
||||||
Using the lib
|
Using the lib
|
||||||
@ -23,3 +23,6 @@ when and how to use them. There are no high-level, single-line scan-a-page-for-m
|
|||||||
At the moment this lib does not provide ways to parse transferred image data and require
|
At the moment this lib does not provide ways to parse transferred image data and require
|
||||||
consumers to do the conversion. The winform project contains one such
|
consumers to do the conversion. The winform project contains one such
|
||||||
example for handling DIB image in native transfer.
|
example for handling DIB image in native transfer.
|
||||||
|
|
||||||
|
The main class to use is TwainSession. New it up, hook into the events, and start calling
|
||||||
|
all the TWAIN functions provided through it.
|
@ -19,7 +19,7 @@ namespace Tester
|
|||||||
{
|
{
|
||||||
// just an amusing example to do twain in console without UI
|
// just an amusing example to do twain in console without UI
|
||||||
DoTwainWork();
|
DoTwainWork();
|
||||||
Console.WriteLine("Test completed, press Enter to exit.");
|
Console.WriteLine("Test started, press Enter to exit.");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@ namespace Tester.Winform
|
|||||||
{
|
{
|
||||||
if (!_loadingCaps && _twain.State == 4)
|
if (!_loadingCaps && _twain.State == 4)
|
||||||
{
|
{
|
||||||
var sel = (int)comboDPI.SelectedItem;
|
var sel = (TWFix32)comboDPI.SelectedItem;
|
||||||
_twain.CapSetDPI(sel);
|
_twain.CapSetDPI(sel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user