mirror of
https://github.com/soukoku/ntwain.git
synced 2026-02-25 13:04:07 +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)]
|
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||||
public struct TW_PENDINGXFERS
|
public struct TW_PENDINGXFERS
|
||||||
{
|
{
|
||||||
|
public TW_PENDINGXFERS()
|
||||||
|
{
|
||||||
|
Count = -1;
|
||||||
|
}
|
||||||
|
|
||||||
public short Count;
|
public short Count;
|
||||||
public uint EOJ;
|
public uint EOJ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,15 @@ namespace NTwain
|
|||||||
return IntPtr.Zero;
|
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.
|
// this handles the message from a typical WndProc message loop and checks if it's for the TWAIN source.
|
||||||
bool handled = false;
|
bool handled = false;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace NTwain
|
|||||||
if (xferImage) imgXferMech = Caps.ICAP_XFERMECH.GetCurrent().FirstOrDefault();
|
if (xferImage) imgXferMech = Caps.ICAP_XFERMECH.GetCurrent().FirstOrDefault();
|
||||||
else if (xferAudio) audXferMech = Caps.ACAP_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));
|
var sts = WrapInSTS(DGControl.PendingXfers.Get(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS)
|
if (sts.RC == TWRC.SUCCESS)
|
||||||
{
|
{
|
||||||
@@ -76,11 +76,13 @@ namespace NTwain
|
|||||||
if (readyArgs.Cancel == CancelType.EndNow || _closeDsRequested)
|
if (readyArgs.Cancel == CancelType.EndNow || _closeDsRequested)
|
||||||
{
|
{
|
||||||
// TODO: need to call EndXfer first?
|
// TODO: need to call EndXfer first?
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
sts = WrapInSTS(DGControl.PendingXfers.Reset(ref _appIdentity, ref _currentDS, ref pending));
|
sts = WrapInSTS(DGControl.PendingXfers.Reset(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS && xferImage) State = STATE.S5;
|
if (sts.RC == TWRC.SUCCESS && xferImage) State = STATE.S5;
|
||||||
}
|
}
|
||||||
else if (readyArgs.Cancel == CancelType.SkipCurrent)
|
else if (readyArgs.Cancel == CancelType.SkipCurrent)
|
||||||
{
|
{
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS)
|
if (sts.RC == TWRC.SUCCESS)
|
||||||
{
|
{
|
||||||
@@ -99,6 +101,7 @@ namespace NTwain
|
|||||||
if (readyArgs.Cancel == CancelType.Graceful)
|
if (readyArgs.Cancel == CancelType.Graceful)
|
||||||
{
|
{
|
||||||
// ignore rc in this and continue transfer as normal
|
// ignore rc in this and continue transfer as normal
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
DGControl.PendingXfers.StopFeeder(ref _appIdentity, ref _currentDS, ref pending);
|
DGControl.PendingXfers.StopFeeder(ref _appIdentity, ref _currentDS, ref pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +180,9 @@ namespace NTwain
|
|||||||
TransferCanceled?.Invoke(this, new TransferCanceledEventArgs());
|
TransferCanceled?.Invoke(this, new TransferCanceledEventArgs());
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
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));
|
sts = WrapInSTS(DGControl.PendingXfers.Reset(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS) State = STATE.S5;
|
if (sts.RC == TWRC.SUCCESS) State = STATE.S5;
|
||||||
break;
|
break;
|
||||||
@@ -192,7 +197,7 @@ namespace NTwain
|
|||||||
case TWCC.NOMEDIA:
|
case TWCC.NOMEDIA:
|
||||||
case TWCC.PAPERDOUBLEFEED:
|
case TWCC.PAPERDOUBLEFEED:
|
||||||
case TWCC.PAPERJAM:
|
case TWCC.PAPERJAM:
|
||||||
pending = default;
|
pending = new TW_PENDINGXFERS();
|
||||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
break;
|
break;
|
||||||
case TWCC.OPERATIONERROR:
|
case TWCC.OPERATIONERROR:
|
||||||
@@ -200,7 +205,9 @@ namespace NTwain
|
|||||||
if (_userInterface.ShowUI == 0 && indicators == TW_BOOL.False)
|
if (_userInterface.ShowUI == 0 && indicators == TW_BOOL.False)
|
||||||
{
|
{
|
||||||
// todo: alert user and drop to S4
|
// todo: alert user and drop to S4
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
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));
|
sts = WrapInSTS(DGControl.PendingXfers.Reset(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -228,7 +235,8 @@ namespace NTwain
|
|||||||
Transferred?.Invoke(this, args);
|
Transferred?.Invoke(this, args);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
;
|
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS)
|
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));
|
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS)
|
if (sts.RC == TWRC.SUCCESS)
|
||||||
{
|
{
|
||||||
@@ -351,6 +360,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
var sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
var sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS)
|
if (sts.RC == TWRC.SUCCESS)
|
||||||
{
|
{
|
||||||
@@ -428,6 +438,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
var sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
var sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS)
|
if (sts.RC == TWRC.SUCCESS)
|
||||||
{
|
{
|
||||||
@@ -456,6 +467,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
|
pending = new TW_PENDINGXFERS();
|
||||||
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS)
|
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));
|
sts = WrapInSTS(DGControl.PendingXfers.EndXfer(ref _appIdentity, ref _currentDS, ref pending));
|
||||||
if (sts.RC == TWRC.SUCCESS)
|
if (sts.RC == TWRC.SUCCESS)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user