Test without HandleRef.

This commit is contained in:
soukoku
2014-04-06 16:45:48 -04:00
parent 45f2302151
commit 05e4eb8504
5 changed files with 15 additions and 17 deletions

View File

@@ -14,6 +14,6 @@ namespace NTwain
// keep this same in majors releases
public const string Release = "0.9.0.0";
// change this for each nuget release
public const string Build = "0.9.0";
public const string Build = "0.9.1";
}
}

View File

@@ -32,7 +32,7 @@ namespace NTwain
}
TWIdentity _appId;
HandleRef _appHandle;
IntPtr _appHandle;
SynchronizationContext _syncer;
object _callbackObj; // kept around so it doesn't get gc'ed
TWUserInterface _twui;
@@ -207,11 +207,11 @@ namespace NTwain
/// <param name="appHandle">On Windows = points to the window handle (hWnd) that will act as the Sources
/// "parent". On Macintosh = should be a NULL value.</param>
/// <returns></returns>
public ReturnCode OpenManager(HandleRef appHandle)
public ReturnCode OpenManager(IntPtr appHandle)
{
Debug.WriteLine(string.Format("Thread {0}: OpenManager.", Thread.CurrentThread.ManagedThreadId));
var rc = DGControl.Parent.OpenDsm(appHandle.Handle);
var rc = DGControl.Parent.OpenDsm(appHandle);
if (rc == ReturnCode.Success)
{
_appHandle = appHandle;
@@ -242,10 +242,10 @@ namespace NTwain
{
Debug.WriteLine(string.Format("Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId));
var rc = DGControl.Parent.CloseDsm(_appHandle.Handle);
var rc = DGControl.Parent.CloseDsm(_appHandle);
if (rc == ReturnCode.Success)
{
_appHandle = default(HandleRef);
_appHandle = IntPtr.Zero;
}
return rc;
}
@@ -307,7 +307,7 @@ namespace NTwain
/// if you do not have a custom one setup.</param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">context</exception>
public ReturnCode EnableSource(SourceEnableMode mode, bool modal, HandleRef windowHandle, SynchronizationContext context)
public ReturnCode EnableSource(SourceEnableMode mode, bool modal, IntPtr windowHandle, SynchronizationContext context)
{
if (context == null) { throw new ArgumentNullException("context"); }
@@ -343,7 +343,7 @@ namespace NTwain
_twui = new TWUserInterface();
_twui.ShowUI = mode == SourceEnableMode.ShowUI;
_twui.ModalUI = modal;
_twui.hParent = windowHandle.Handle;
_twui.hParent = windowHandle;
if (mode == SourceEnableMode.ShowUIOnly)
{

View File

@@ -53,7 +53,7 @@ namespace Tester
mySyncer = new DispatcherSynchronizationContext(obj as Dispatcher);
}
var rc = twain.OpenManager(default(HandleRef));
var rc = twain.OpenManager(IntPtr.Zero);
if (rc == ReturnCode.Success)
{
@@ -64,7 +64,7 @@ namespace Tester
// enablesource must be on the thread the sync context works on
mySyncer.Post(blah =>
{
rc = twain.EnableSource(SourceEnableMode.NoUI, false, default(HandleRef), blah as SynchronizationContext);
rc = twain.EnableSource(SourceEnableMode.NoUI, false, IntPtr.Zero, blah as SynchronizationContext);
}, mySyncer);
return;
}

View File

@@ -100,7 +100,7 @@ namespace Tester.WPF
string step = "Open DSM";
HandleRef hand = new HandleRef(this, new WindowInteropHelper(Application.Current.MainWindow).Handle);
var hand = new WindowInteropHelper(Application.Current.MainWindow).Handle;
var rc = twain.OpenManager(hand);
if (rc == ReturnCode.Success)

View File

@@ -159,13 +159,12 @@ namespace Tester.Winform
{
if (_twain.State == 4)
{
var hand = new HandleRef(this, this.Handle);
_stopScan = false;
if (_twain.SupportedCaps.Contains(CapabilityId.CapUIControllable))
{
// hide scanner ui if possible
if (_twain.EnableSource(SourceEnableMode.NoUI, false, hand, SynchronizationContext.Current) == ReturnCode.Success)
if (_twain.EnableSource(SourceEnableMode.NoUI, false, this.Handle, SynchronizationContext.Current) == ReturnCode.Success)
{
btnStopScan.Enabled = true;
btnStartCapture.Enabled = false;
@@ -174,7 +173,7 @@ namespace Tester.Winform
}
else
{
if (_twain.EnableSource(SourceEnableMode.ShowUI, false, hand, SynchronizationContext.Current) == ReturnCode.Success)
if (_twain.EnableSource(SourceEnableMode.ShowUI, true, this.Handle, SynchronizationContext.Current) == ReturnCode.Success)
{
btnStopScan.Enabled = true;
btnStartCapture.Enabled = false;
@@ -230,7 +229,7 @@ namespace Tester.Winform
{
if (_twain.State < 3)
{
_twain.OpenManager(new HandleRef(this, this.Handle));
_twain.OpenManager(this.Handle);
}
if (_twain.State >= 3)
@@ -357,8 +356,7 @@ namespace Tester.Winform
private void btnAllSettings_Click(object sender, EventArgs e)
{
var hand = new HandleRef(this, this.Handle);
_twain.EnableSource(SourceEnableMode.ShowUIOnly, true, hand, SynchronizationContext.Current);
_twain.EnableSource(SourceEnableMode.ShowUIOnly, true, this.Handle, SynchronizationContext.Current);
}
#endregion