コード例 #1
0
ファイル: TWAINCSTool.cs プロジェクト: edonosotti/ScanToCloud
        /// <summary>
        /// Handle DG_CONTROL / DAT_SETUPFILEXFER / MSG_*
        /// </summary>
        /// <param name="a_dg">Data group</param>
        /// <param name="a_msg">Operation</param>
        /// <param name="a_szStatus">Result of operation</param>
        /// <param name="a_szMemref">Pointer to data</param>
        /// <returns>TWAIN status</returns>
        private STS SendDatSetupfilexfer(TWAIN.DG a_dg, TWAIN.MSG a_msg, ref string a_szStatus, ref string a_szMemref)
        {
            TWAIN.STS sts;
            TWAIN.TW_SETUPFILEXFER twsetupfilexfer;

            // Clear or get...
            a_szStatus = "";
            twsetupfilexfer = default(TWAIN.TW_SETUPFILEXFER);
            if (a_msg == TWAIN.MSG.SET)
            {
                if (!m_twain.CsvToSetupfilexfer(ref twsetupfilexfer, a_szMemref))
                {
                    return (STS.BADVALUE);
                }
            }

            // Issue the command...
            sts = m_twain.DatSetupfilexfer(a_dg, a_msg, ref twsetupfilexfer);
            if (sts == TWAIN.STS.SUCCESS)
            {
                // Get the data...
                a_szMemref = m_twain.SetupfilexferToCsv(twsetupfilexfer);

                // Squirrel this away for DAT_IMAGEFILEXFER...
                m_twsetupfilexfer = twsetupfilexfer;
            }

            // All done...
            return (CvtSts(sts));
        }
コード例 #2
0
ファイル: TWAINCSTool.cs プロジェクト: edonosotti/ScanToCloud
        /// <summary>
        /// Instantiate TWAIN and open the DSM...
        /// </summary>
        /// <param name="a_intptrHwnd">Parent window (needed for Windows)</param>
        /// <param name="a_writeoutputdelegate">Optional text output callback</param>
        /// <param name="a_reportimagedelegate">Optional report image callback</param>
        /// <param name="m_setmessagefilterdelegate">Optional message filter callback</param>
        /// <param name="a_szManufacturer">Application manufacturer</param>
        /// <param name="a_szProductFamily">Application family</param>
        /// <param name="a_szProductName">Name of the application</param>
        /// <param name="a_u16ProtocolMajor">TWAIN protocol major (doesn't have to match TWAINH.CS)</param>
        /// <param name="a_u16ProtocolMinor">TWAIN protocol minor (doesn't have to match TWAINH.CS)</param>
        /// <param name="a_aszSupportedGroups">Bitmask of DG_ flags</param>
        /// <param name="a_szTwcy">Application's country code</param>
        /// <param name="a_szInfo">Info about the application</param>
        /// <param name="a_szTwlg">Application's language</param>
        /// <param name="a_u16MajorNum">Application's major version</param>
        /// <param name="a_u16MinorNum">Application's minor version</param>
        /// <param name="a_blUseLegacyDSM">The the legacy DSM (like TWAIN_32.DLL)</param>
        /// <param name="a_blUseCallbacks">Use callbacks (preferred)</param>
        public TWAINCSToolkit(
            IntPtr a_intptrHwnd,
            WriteOutputDelegate a_writeoutputdelegate,
            ReportImageDelegate a_reportimagedelegate,
            SetMessageFilterDelegate m_setmessagefilterdelegate,
            string a_szManufacturer,
            string a_szProductFamily,
            string a_szProductName,
            ushort a_u16ProtocolMajor,
            ushort a_u16ProtocolMinor,
            string[] a_aszSupportedGroups,
            string a_szTwcy,
            string a_szInfo,
            string a_szTwlg,
            ushort a_u16MajorNum,
            ushort a_u16MinorNum,
            bool a_blUseLegacyDSM,
            bool a_blUseCallbacks
        )
        {
            TWAIN.STS sts;
            uint u32SupportedGroups;

            // Init stuff...
            m_intptrHwnd = a_intptrHwnd;
            if (a_writeoutputdelegate == null)
            {
                WriteOutput = WriteOutputStub;
            }
            else
            {
                WriteOutput = a_writeoutputdelegate;
            }
            ReportImage = a_reportimagedelegate;
            SetMessageFilter = m_setmessagefilterdelegate;
            m_szImagePath = null;
            m_iImageCount = 0;

            // Convert the supported groups from strings to flags...
            u32SupportedGroups = 0;
            foreach (string szSupportedGroup in a_aszSupportedGroups)
            {
                TWAIN.DG dg = (TWAIN.DG)Enum.Parse(typeof(TWAIN.DG), szSupportedGroup.Remove(0, 3));
                if (Enum.IsDefined(typeof(TWAIN.DG), dg))
                {
                    u32SupportedGroups |= (uint)dg;
                }
            }

            // Instantiate TWAIN, and register ourselves...
            m_twain = new TWAIN
            (
                a_szManufacturer,
                a_szProductFamily,
                a_szProductName,
                a_u16ProtocolMajor,
                a_u16ProtocolMinor,
                u32SupportedGroups,
                (TWAIN.TWCY)Enum.Parse(typeof(TWAIN.TWCY), a_szTwcy),
                a_szInfo,
                (TWAIN.TWLG)Enum.Parse(typeof(TWAIN.TWLG), a_szTwlg),
                a_u16MajorNum,
                a_u16MinorNum,
                a_blUseLegacyDSM,
                a_blUseCallbacks,
                DeviceEventCallback,
                ScanCallback
            );

            // Store some values...
            m_blUseCallbacks = a_blUseCallbacks;

            // Our default transfer mechanism...
            m_twsxXferMech = TWAIN.TWSX.NATIVE;

            // Our default file transfer info...
            m_twsetupfilexfer = default(TWAIN.TW_SETUPFILEXFER);
            m_twsetupfilexfer.Format = TWAIN.TWFF.TIFF;
            if (TWAIN.GetPlatform() == TWAIN.Platform.WINDOWS)
            {
                m_twsetupfilexfer.FileName.Set(Path.GetTempPath() + "img");
            }
            else if (TWAIN.GetPlatform() == TWAIN.Platform.LINUX)
            {
                m_twsetupfilexfer.FileName.Set(Path.GetTempPath() + "img");
            }
            else if (TWAIN.GetPlatform() == TWAIN.Platform.MACOSX)
            {
                m_twsetupfilexfer.FileName.Set("/var/tmp/img");
            }
            else
            {
                Log.Msg(Log.Severity.Throw, "Unsupported platform..." + TWAIN.GetPlatform());
            }

            // We've not been in the scan callback yet...
            m_blScanStart = true;

            // Open the DSM...
            try
            {
                sts = m_twain.DatParent(TWAIN.DG.CONTROL, TWAIN.MSG.OPENDSM, ref m_intptrHwnd);
            }
            catch (Exception exception)
            {
                Log.Msg(Log.Severity.Error, "OpenDSM exception: " + exception.Message);
                sts = TWAIN.STS.FAILURE;
            }
            if (sts != TWAIN.STS.SUCCESS)
            {
                Log.Msg(Log.Severity.Error, "OpenDSM failed...");
                Cleanup();
                throw new Exception("OpenDSM failed...");
            }
        }