mirror of
https://github.com/soukoku/ntwain.git
synced 2026-01-09 19:24:40 +08:00
Expose wndproc hook method and test reset TW_PENDINGXFERS before use.
This commit is contained in:
@@ -2426,6 +2426,11 @@ namespace NTwain.Data
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
public struct TW_PENDINGXFERS
|
||||
{
|
||||
public TW_PENDINGXFERS()
|
||||
{
|
||||
Count = -1;
|
||||
}
|
||||
|
||||
public short Count;
|
||||
public uint EOJ;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,15 @@ namespace NTwain
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
private bool WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
|
||||
/// <summary>
|
||||
/// Method to check window message and handle it if it's for the TWAIN source.'
|
||||
/// </summary>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <param name="wParam"></param>
|
||||
/// <param name="lParam"></param>
|
||||
/// <returns></returns>
|
||||
public bool WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
// this handles the message from a typical WndProc message loop and checks if it's for the TWAIN source.
|
||||
bool handled = false;
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace NTwain
|
||||
if (xferImage) imgXferMech = Caps.ICAP_XFERMECH.GetCurrent().FirstOrDefault();
|
||||
else if (xferAudio) audXferMech = Caps.ACAP_XFERMECH.GetCurrent().FirstOrDefault();
|
||||
|
||||
TW_PENDINGXFERS pending = default;
|
||||
TW_PENDINGXFERS pending = new TW_PENDINGXFERS();
|
||||
var sts = WrapInSTS(DGControl.PendingXfers.Get(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS)
|
||||
{
|
||||
@@ -76,11 +76,13 @@ namespace NTwain
|
||||
if (readyArgs.Cancel == CancelType.EndNow || _closeDsRequested)
|
||||
{
|
||||
// TODO: need to call EndXfer first?
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.Reset(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS && xferImage) State = STATE.S5;
|
||||
}
|
||||
else if (readyArgs.Cancel == CancelType.SkipCurrent)
|
||||
{
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS)
|
||||
{
|
||||
@@ -99,6 +101,7 @@ namespace NTwain
|
||||
if (readyArgs.Cancel == CancelType.Graceful)
|
||||
{
|
||||
// ignore rc in this and continue transfer as normal
|
||||
pending = new TW_PENDINGXFERS();
|
||||
DGControl.PendingXfers.StopFeeder(ref _appIdentity, ref _currentDS, ref pending);
|
||||
}
|
||||
|
||||
@@ -177,7 +180,9 @@ namespace NTwain
|
||||
TransferCanceled?.Invoke(this, new TransferCanceledEventArgs());
|
||||
}
|
||||
catch { }
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.Reset(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS) State = STATE.S5;
|
||||
break;
|
||||
@@ -192,7 +197,7 @@ namespace NTwain
|
||||
case TWCC.NOMEDIA:
|
||||
case TWCC.PAPERDOUBLEFEED:
|
||||
case TWCC.PAPERJAM:
|
||||
pending = default;
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
break;
|
||||
case TWCC.OPERATIONERROR:
|
||||
@@ -200,7 +205,9 @@ namespace NTwain
|
||||
if (_userInterface.ShowUI == 0 && indicators == TW_BOOL.False)
|
||||
{
|
||||
// todo: alert user and drop to S4
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.Reset(ref _appIdentity, ref _currentDS, ref pending));
|
||||
}
|
||||
break;
|
||||
@@ -228,7 +235,8 @@ namespace NTwain
|
||||
Transferred?.Invoke(this, args);
|
||||
}
|
||||
catch { }
|
||||
;
|
||||
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS)
|
||||
{
|
||||
@@ -268,6 +276,7 @@ namespace NTwain
|
||||
}
|
||||
}
|
||||
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS)
|
||||
{
|
||||
@@ -351,6 +360,7 @@ namespace NTwain
|
||||
}
|
||||
catch { }
|
||||
|
||||
pending = new TW_PENDINGXFERS();
|
||||
var sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS)
|
||||
{
|
||||
@@ -428,6 +438,7 @@ namespace NTwain
|
||||
}
|
||||
catch { }
|
||||
|
||||
pending = new TW_PENDINGXFERS();
|
||||
var sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS)
|
||||
{
|
||||
@@ -456,6 +467,7 @@ namespace NTwain
|
||||
}
|
||||
catch { }
|
||||
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS)
|
||||
{
|
||||
@@ -509,6 +521,7 @@ namespace NTwain
|
||||
}
|
||||
|
||||
|
||||
pending = new TW_PENDINGXFERS();
|
||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||
if (sts.RC == TWRC.SUCCESS)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user