diff --git a/NTwain.Net35/NTwain.Net35.csproj b/NTwain.Net35/NTwain.Net35.csproj new file mode 100644 index 0000000..5c0a7c8 --- /dev/null +++ b/NTwain.Net35/NTwain.Net35.csproj @@ -0,0 +1,281 @@ + + + + + Debug + AnyCPU + {2E965494-94B0-4EC7-960C-24E5D7D04278} + Library + Properties + NTwain + NTwain + v3.5 + 512 + Client + + + true + full + false + ..\NTwain\bin\Debug\Net35\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\NTwain\bin\Release\Net35\ + TRACE + prompt + 4 + ..\NTwain\bin\Release\Net35\NTwain.XML + + + true + + + Sign.snk + + + + + + + + + DataTransferredEventArgs.cs + + + Data\CapReadOut.cs + + + Data\TypeReader.cs + + + Data\Types.cs + + + Data\TypesExtended.cs + + + DeviceEventArgs.cs + + + Extensions.cs + + + IMemoryManager.cs + + + ITwainOperation.cs + + + ITwainState.cs + + + MemoryManager.cs + + + MessageLoop.cs + + + NativeMethods.cs + + + Properties\AssemblyInfo.cs + + + Properties\Resources.Designer.cs + Resources.resx + True + True + + + Properties\VersionInfo.cs + + + TentativeStateCommitable.cs + + + TransferErrorEventArgs.cs + + + TransferReadyEventArgs.cs + + + Triplets\DGAudio\DGAudio.AudioFileXfer.cs + + + Triplets\DGAudio\DGAudio.AudioInfo.cs + + + Triplets\DGAudio\DGAudio.AudioNativeXfer.cs + + + Triplets\DGAudio\DGAudio.cs + + + Triplets\DGControl\DGControl.Callback.cs + + + Triplets\DGControl\DGControl.Callback2.cs + + + Triplets\DGControl\DGControl.Capability.cs + + + Triplets\DGControl\DGControl.cs + + + Triplets\DGControl\DGControl.CustomDSData.cs + + + Triplets\DGControl\DGControl.DeviceEvent.cs + + + Triplets\DGControl\DGControl.EntryPoint.cs + + + Triplets\DGControl\DGControl.Event.cs + + + Triplets\DGControl\DGControl.FileSystem.cs + + + Triplets\DGControl\DGControl.Identity.cs + + + Triplets\DGControl\DGControl.Parent.cs + + + Triplets\DGControl\DGControl.PassThru.cs + + + Triplets\DGControl\DGControl.PendingXfers.cs + + + Triplets\DGControl\DGControl.SetupFileXfer.cs + + + Triplets\DGControl\DGControl.SetupMemXfer.cs + + + Triplets\DGControl\DGControl.Status.cs + + + Triplets\DGControl\DGControl.StatusUtf8.cs + + + Triplets\DGControl\DGControl.UserInterface.cs + + + Triplets\DGControl\DGControl.XferGroup.cs + + + Triplets\DGImage\DGImage.CieColor.cs + + + Triplets\DGImage\DGImage.cs + + + Triplets\DGImage\DGImage.ExtImageInfo.cs + + + Triplets\DGImage\DGImage.Filter.cs + + + Triplets\DGImage\DGImage.GrayResponse.cs + + + Triplets\DGImage\DGImage.IccProfile.cs + + + Triplets\DGImage\DGImage.ImageFileXfer.cs + + + Triplets\DGImage\DGImage.ImageInfo.cs + + + Triplets\DGImage\DGImage.ImageLayout.cs + + + Triplets\DGImage\DGImage.ImageMemFileXfer.cs + + + Triplets\DGImage\DGImage.ImageMemXfer.cs + + + Triplets\DGImage\DGImage.ImageNativeXfer.cs + + + Triplets\DGImage\DGImage.JpegCompression.cs + + + Triplets\DGImage\DGImage.Palette8.cs + + + Triplets\DGImage\DGImage.RgbResponse.cs + + + Triplets\Dsm.cs + + + Triplets\Dsm.Linux.cs + + + Triplets\Dsm.WinNew.cs + + + Triplets\Dsm.WinOld.cs + + + Triplets\OpBase.cs + + + TwainException.cs + + + TwainSession.cs + + + TwainSessionExtensions.cs + + + TwainStateException.cs + + + Values\DataValues.cs + + + Values\SourceEnableMode.cs + + + Values\TwainConst.cs + + + Values\ValueConverter.cs + + + + + Properties\Resources.resx + ResXFileCodeGenerator + Resources.Designer.cs + + + + + Triplets\WhatsThis.txt + + + + + + \ No newline at end of file diff --git a/NTwain.Net35/Sign.snk b/NTwain.Net35/Sign.snk new file mode 100644 index 0000000..d65a7a6 Binary files /dev/null and b/NTwain.Net35/Sign.snk differ diff --git a/NTwain.sln b/NTwain.sln index ee6934e..1d94121 100644 --- a/NTwain.sln +++ b/NTwain.sln @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Others", "Others", "{4CE0B9 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tester.Console", "Tests\Tester.Console\Tester.Console.csproj", "{12D761EF-68DF-41CE-92EF-0C7AE81857A3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTwain.Net35", "NTwain.Net35\NTwain.Net35.csproj", "{2E965494-94B0-4EC7-960C-24E5D7D04278}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -81,6 +83,16 @@ Global {12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|Mixed Platforms.Build.0 = Release|Any CPU {12D761EF-68DF-41CE-92EF-0C7AE81857A3}.Release|x86.ActiveCfg = Release|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Debug|x86.ActiveCfg = Debug|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|Any CPU.Build.0 = Release|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {2E965494-94B0-4EC7-960C-24E5D7D04278}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NTwain/Data/TypesExtended.cs b/NTwain/Data/TypesExtended.cs index 5486cc1..43eae7a 100644 --- a/NTwain/Data/TypesExtended.cs +++ b/NTwain/Data/TypesExtended.cs @@ -707,7 +707,7 @@ namespace NTwain.Data ContainerType = Values.ContainerType.Enum; - Int32 valueSize = value.ItemOffset + value.ItemList.Length * TypeReader.GetItemTypeSize(value.ItemType); + Int32 valueSize = TWEnumeration.ItemOffset + value.ItemList.Length * TypeReader.GetItemTypeSize(value.ItemType); int offset = 0; _hContainer = MemoryManager.Instance.Allocate((uint)valueSize); @@ -817,7 +817,7 @@ namespace NTwain.Data /// /// /// - private void WriteString(IntPtr baseAddr, int offset, string item, int maxLength) + static void WriteString(IntPtr baseAddr, int offset, string item, int maxLength) { if (string.IsNullOrEmpty(item)) { @@ -1262,7 +1262,7 @@ namespace NTwain.Data /// /// Gets the byte offset of the item list from a Ptr to the first item. /// - internal int ItemOffset { get { return 14; } } + internal const int ItemOffset = 14; } @@ -1686,7 +1686,7 @@ namespace NTwain.Data } /// - /// Creates a from specified values. + /// Creates a from specified values. /// /// The supported groups. /// The version. @@ -1695,9 +1695,12 @@ namespace NTwain.Data /// Name of the product. /// The product description. /// + /// version public static TWIdentity Create(DataGroups supportedGroups, Version version, string manufacturer, string productFamily, string productName, string productDescription) { + if (version == null) { throw new ArgumentNullException("version"); } + return new TWIdentity { Manufacturer = string.IsNullOrEmpty(manufacturer) ? "UNKNOWN" : manufacturer, @@ -1796,7 +1799,7 @@ namespace NTwain.Data /// The compression method used to process the data being transferred. /// Default is no compression. /// - public Compression Compression { get { return (Values.Compression)_compression; } } + public CompressionType Compression { get { return (Values.CompressionType)_compression; } } } /// @@ -1877,7 +1880,7 @@ namespace NTwain.Data /// /// The compression method used to process the data being transferred. /// - public Compression Compression { get { return (Compression)_compression; } } + public CompressionType Compression { get { return (CompressionType)_compression; } } /// /// The number of uncompressed bytes in each row of the piece of the image /// being described in this buffer. @@ -2221,10 +2224,10 @@ namespace NTwain.Data /// TwIdentity.Language or CapLanguage). The Source allocates /// it, the Application frees it. /// - IntPtr UTF8StringPtr { get { return _uTF8string; } } + public IntPtr UTF8StringPtr { get { return _uTF8string; } } /// - /// Gets the actual string from the pointer. + /// Gets the actual string from the pointer. This may be incorrect. /// /// public string GetActualString() diff --git a/NTwain/MessageLoop.cs b/NTwain/MessageLoop.cs index 32b01fc..51c8624 100644 --- a/NTwain/MessageLoop.cs +++ b/NTwain/MessageLoop.cs @@ -26,7 +26,7 @@ namespace NTwain if (_dispatcher == null) { // using this terrible hack so the new thread will start running before this function returns - using (var hack = new ManualResetEvent(false)) + using (var hack = new WrappedManualResetEvent()) { var loopThread = new Thread(new ThreadStart(() => { @@ -49,7 +49,7 @@ namespace NTwain loopThread.IsBackground = true; loopThread.SetApartmentState(ApartmentState.STA); loopThread.Start(); - hack.WaitOne(); + hack.Wait(); } } } @@ -79,7 +79,7 @@ namespace NTwain } else if (Dsm.IsOnMono) { - using (var man = new ManualResetEvent(false)) + using (var man = new WrappedManualResetEvent()) { _dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { @@ -92,7 +92,7 @@ namespace NTwain man.Set(); } })); - man.WaitOne(); + man.Wait(); } } else @@ -117,16 +117,24 @@ namespace NTwain // hook into windows msg loop for old twain to post msgs. // the style values are purely guesses here with // CS_NOCLOSE, WS_DISABLED, and WS_EX_NOACTIVATE - var win = new HwndSource(0x0200, 0x8000000, 0x8000000, 0, 0, "NTWAIN_LOOPER", IntPtr.Zero); - Handle = win.Handle; - win.AddHook(WndProc); - _win = win; - _hook = hook; + HwndSource win = null; + try + { + win = new HwndSource(0x0200, 0x8000000, 0x8000000, 0, 0, "NTWAIN_LOOPER", IntPtr.Zero); + Handle = win.Handle; + win.AddHook(WndProc); + _win = win; + _hook = hook; + } + catch + { + if (win != null) { win.Dispose(); } + } } public delegate void WndProcHook(ref MESSAGE winMsg, ref bool handled); - + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (_hook != null) @@ -180,4 +188,55 @@ namespace NTwain #endregion } + + // just a test + + class WrappedManualResetEvent : IDisposable + { +#if NET4 + ManualResetEventSlim _slim; +#else + ManualResetEvent _mre; +#endif + + public WrappedManualResetEvent() + { +#if NET4 + _slim = new ManualResetEventSlim(); +#else + _mre = new ManualResetEvent(false); +#endif + } + + public void Wait() + { +#if NET4 + _slim.Wait(); +#else + _mre.WaitOne(); +#endif + } + + public void Set() + { +#if NET4 + _slim.Set(); +#else + _mre.Set(); +#endif + } + + #region IDisposable Members + + public void Dispose() + { +#if NET4 + _slim.Dispose(); +#else + _mre.Close(); +#endif + } + + #endregion + } } diff --git a/NTwain/NTwain.csproj b/NTwain/NTwain.csproj index 51c3e09..3baf06a 100644 --- a/NTwain/NTwain.csproj +++ b/NTwain/NTwain.csproj @@ -10,7 +10,7 @@ Properties NTwain NTwain - v3.5 + v4.0 512 ..\ Client @@ -33,11 +33,12 @@ pdbonly true bin\Release\ - TRACE;WIN32 + TRACE;NET4 prompt 4 bin\Release\NTwain.xml true + AllRules.ruleset true @@ -48,8 +49,6 @@ - - diff --git a/NTwain/NTwain.nuspec b/NTwain/NTwain.nuspec index b372e47..b913177 100644 --- a/NTwain/NTwain.nuspec +++ b/NTwain/NTwain.nuspec @@ -16,9 +16,9 @@ twain scan - - + + + + \ No newline at end of file diff --git a/NTwain/Triplets/Dsm.cs b/NTwain/Triplets/Dsm.cs index fda8ac7..40606b3 100644 --- a/NTwain/Triplets/Dsm.cs +++ b/NTwain/Triplets/Dsm.cs @@ -1,6 +1,7 @@ using NTwain.Data; using NTwain.Values; using System; +using System.IO; namespace NTwain.Triplets { @@ -27,9 +28,8 @@ namespace NTwain.Triplets return IntPtr.Size == 8; #else var path = Path.Combine(Environment.SystemDirectory, "twaindsm.dll"); - // if 64bit or the dll exists use it - return IntPtr.Size == 8 || - File.Exists(path); + // if 64bit or the new dll exists use it + return IntPtr.Size == 8 || File.Exists(path); #endif } internal static readonly bool IsOnMono = Type.GetType("Mono.Runtime") != null; diff --git a/NTwain/TwainSessionExtensions.cs b/NTwain/TwainSessionExtensions.cs index 68424a7..f2f2622 100644 --- a/NTwain/TwainSessionExtensions.cs +++ b/NTwain/TwainSessionExtensions.cs @@ -213,14 +213,14 @@ namespace NTwain #region compression /// - /// Gets the supported for the current source. + /// Gets the supported for the current source. /// Only call this at state 4 or higher. /// /// The session. /// - public static IList CapGetCompression(this TwainSession session) + public static IList CapGetCompression(this TwainSession session) { - return session.GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum(true); + return session.GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum(true); } /// @@ -229,7 +229,7 @@ namespace NTwain /// The session. /// The compression. /// - public static ReturnCode CapSetImageCompression(this TwainSession session, Compression compression) + public static ReturnCode CapSetImageCompression(this TwainSession session, CompressionType compression) { using (TWCapability compressCap = new TWCapability(CapabilityId.ICapCompression, new TWOneValue { Item = (uint)compression, ItemType = Values.ItemType.UInt16 })) { diff --git a/NTwain/Values/DataValues.cs b/NTwain/Values/DataValues.cs index 23b51df..2c7b764 100644 --- a/NTwain/Values/DataValues.cs +++ b/NTwain/Values/DataValues.cs @@ -267,7 +267,7 @@ namespace NTwain.Values /// setting the desired file format with ICAP_IMAGEFILEFORMAT. /// Corresponds to TWCP_* values. /// - public enum Compression : ushort + public enum CompressionType : ushort { /// /// All Sources must support this. diff --git a/Tests/Tester.WPF/MainWindow.xaml.cs b/Tests/Tester.WPF/MainWindow.xaml.cs index af77aa7..9373beb 100644 --- a/Tests/Tester.WPF/MainWindow.xaml.cs +++ b/Tests/Tester.WPF/MainWindow.xaml.cs @@ -426,7 +426,7 @@ namespace Tester.WPF CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap); break; case CapabilityId.ICapCompression: - CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum(); + CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap).CastToEnum(); break; case CapabilityId.ICapContrast: CapDetailList.ItemsSource = _twainVM.GetCapabilityValues(cap); diff --git a/Tests/Tester.Winform/Tester.Winform.csproj b/Tests/Tester.Winform/Tester.Winform.csproj index ae7f0d3..da25935 100644 --- a/Tests/Tester.Winform/Tester.Winform.csproj +++ b/Tests/Tester.Winform/Tester.Winform.csproj @@ -79,9 +79,9 @@ - - {0C5A6FB1-0282-4D61-8354-68DEB1515001} - NTwain + + {2e965494-94b0-4ec7-960c-24e5d7d04278} + NTwain.Net35