Fix 32bit error and tweak message format in console.

This commit is contained in:
Eugene Wang
2025-11-12 07:51:43 -05:00
parent da76306bcf
commit 02c722f964
2 changed files with 7 additions and 7 deletions

View File

@@ -127,13 +127,13 @@ namespace WinConsole32
} }
static int xferCount = 0; static int xferCount = 0;
static Stopwatch watch; static Stopwatch watch = new Stopwatch();
private static void Session_Transferred(TwainAppSession twain, TransferredEventArgs e) private static void Session_Transferred(TwainAppSession twain, TransferredEventArgs e)
{ {
if (e.Data != null) if (e.Data != null)
{ {
var saveFile = $"twain_{DateTime.Now:yyyyMMdd_HHmmss}_{xferCount}"; var saveFile = $"twain_{DateTime.Now:yyyyMMdd_HHmmss}_{xferCount}";
Console.WriteLine("SUCCESS! Got twain memory data #{0} on thread {1}, saving to {saveFile}.", ++xferCount, Environment.CurrentManagedThreadId, saveFile); Console.WriteLine($"SUCCESS! Got twain memory data #{++xferCount} on thread {Environment.CurrentManagedThreadId}, saving to {saveFile}.");
using (var img = new ImageMagick.MagickImage(e.Data.AsStream())) using (var img = new ImageMagick.MagickImage(e.Data.AsStream()))
{ {
@@ -157,11 +157,11 @@ namespace WinConsole32
else if (e.FileInfo != null) else if (e.FileInfo != null)
{ {
var fi = e.FileInfo.Value; var fi = e.FileInfo.Value;
Console.WriteLine("SUCCESS! Got twain file data #{0} on thread {1} as {saveFile}.", ++xferCount, Environment.CurrentManagedThreadId, fi.FileName); Console.WriteLine($"SUCCESS! Got twain file data #{++xferCount} on thread {Environment.CurrentManagedThreadId} as {fi.FileName}.");
} }
else else
{ {
Console.WriteLine("BUMMER! No twain data #{0} on thread {1}.", ++xferCount, Environment.CurrentManagedThreadId); Console.WriteLine($"BUMMER! No twain data #{++xferCount} on thread {Environment.CurrentManagedThreadId}.");
} }
e.Dispose(); e.Dispose();
} }
@@ -199,10 +199,10 @@ namespace WinConsole32
twain.Caps.ICAP_PIXELTYPE.Set(TWPT.RGB); twain.Caps.ICAP_PIXELTYPE.Set(TWPT.RGB);
twain.Caps.ICAP_XRESOLUTION.Set(300f); twain.Caps.ICAP_XRESOLUTION.Set(300f);
twain.Caps.ICAP_YRESOLUTION.Set(300f); twain.Caps.ICAP_YRESOLUTION.Set(300f);
twain.Caps.CAP_XFERCOUNT.Set(100); twain.Caps.CAP_XFERCOUNT.Set(4);
xferCount = 0; xferCount = 0;
watch = Stopwatch.StartNew(); watch.Restart();
var rc = twain.EnableSource(true, false); var rc = twain.EnableSource(true, false);
} }
} }

View File

@@ -88,7 +88,7 @@ namespace NTwain
{ {
hwnd = (HWND)hWnd, hwnd = (HWND)hWnd,
message = (uint)msg, message = (uint)msg,
wParam = (UIntPtr)wParam.ToInt64(), wParam = TWPlatform.Is32bit ? new UIntPtr((uint)wParam.ToInt32()) : new UIntPtr((ulong)wParam.ToInt64()),
lParam = lParam lParam = lParam
}; };
// no need to do another lock call when using marshal alloc // no need to do another lock call when using marshal alloc