public static extern ReturnCode DsmWin32( [In, Out] TW_IDENTITY origin, [In, Out] TW_IDENTITY destination, DataGroups dg, DataArgumentType dat, Message msg, ref TW_SETUPFILEXFER data);
ReturnCode DoIt(Message msg, ref TW_SETUPFILEXFER xfer) { if (Is32Bit) { if (IsWin) { return(NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, ref xfer)); } if (IsLinux) { return(NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, ref xfer)); } if (IsMac) { return(NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, ref xfer)); } } if (IsWin) { return(NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, ref xfer)); } if (IsLinux) { return(NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, ref xfer)); } if (IsMac) { return(NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.SetupFileXfer, msg, ref xfer)); } return(ReturnCode.Failure); }
/// <summary> /// Get/Set for a file xfer... /// </summary> /// <param name="a_dg">Data group</param> /// <param name="a_msg">Operation</param> /// <param name="a_twsetupfilexfer">SETUPFILEXFER structure</param> /// <returns>TWAIN status</returns> public STS DatSetupfilexfer(DG a_dg, MSG a_msg, ref TW_SETUPFILEXFER a_twsetupfilexfer) { STS sts; // Submit the work to the TWAIN thread... if ((m_threadTwain != null) && (m_threadTwain.ManagedThreadId != Thread.CurrentThread.ManagedThreadId)) { lock (m_lockTwain) { // Set our command variables... ThreadData threaddata = default(ThreadData); threaddata.twsetupfilexfer = a_twsetupfilexfer; threaddata.dg = a_dg; threaddata.msg = a_msg; threaddata.dat = DAT.SETUPFILEXFER; long lIndex = m_twaincommand.Submit(threaddata); // Submit the command and wait for the reply... CallerToThreadSet(); ThreadToCallerWaitOne(); // Return the result... a_twsetupfilexfer = m_twaincommand.Get(lIndex).twsetupfilexfer; sts = m_twaincommand.Get(lIndex).sts; // Clear the command variables... m_twaincommand.Delete(lIndex); } return (sts); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendBefore(a_dg.ToString(), DAT.SETUPFILEXFER.ToString(), a_msg.ToString(), SetupfilexferToCsv(a_twsetupfilexfer)); } // Windows... if (ms_platform == Platform.WINDOWS) { // Issue the command... try { if (m_blUseLegacyDSM) { sts = (STS)WindowsTwain32DsmEntrySetupfilexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.SETUPFILEXFER, a_msg, ref a_twsetupfilexfer); } else { sts = (STS)WindowsTwaindsmDsmEntrySetupfilexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.SETUPFILEXFER, a_msg, ref a_twsetupfilexfer); } } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } } // Linux... else if (ms_platform == Platform.LINUX) { // Issue the command... try { if (GetMachineWordBitSize() == 32) { sts = (STS)LinuxDsmEntrySetupfilexfer(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.SETUPFILEXFER, a_msg, ref a_twsetupfilexfer); } else { sts = (STS)Linux64DsmEntrySetupfilexfer(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.SETUPFILEXFER, a_msg, ref a_twsetupfilexfer); } } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } } // Mac OS X, which has to be different... else if (ms_platform == Platform.MACOSX) { // Issue the command... try { sts = (STS)MacosxDsmEntrySetupfilexfer(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.SETUPFILEXFER, a_msg, ref a_twsetupfilexfer); } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } } // Uh-oh... else { Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendAfter(sts.ToString(), SetupfilexferToCsv(a_twsetupfilexfer)); } // All done... return (AutoDatStatus(sts)); }
/// <summary> /// Convert a string to a setupfilexfer... /// </summary> /// <param name="a_twsetupfilexfer">A TWAIN structure</param> /// <param name="a_szSetupfilexfer">A CSV string of the TWAIN structure</param> /// <returns>True if the conversion is successful</returns> public bool CsvToSetupfilexfer(ref TW_SETUPFILEXFER a_twsetupfilexfer, string a_szSetupfilexfer) { // Init stuff... a_twsetupfilexfer = default(TW_SETUPFILEXFER); // Build the string... try { string[] asz = CSV.Parse(a_szSetupfilexfer); // Sort out the values... a_twsetupfilexfer.FileName.Set(asz[0]); a_twsetupfilexfer.Format = (TWFF)Enum.Parse(typeof(TWFF), asz[1].Remove(0, 5)); a_twsetupfilexfer.VRefNum = short.Parse(asz[2]); } catch { return (false); } // All done... return (true); }
/// <summary> /// Convert the contents of a setup file xfer structure to a string that /// we can show in our simple GUI... /// </summary> /// <param name="a_twsetupfilexfer">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string SetupfilexferToCsv(TW_SETUPFILEXFER a_twsetupfilexfer) { try { CSV csv = new CSV(); csv.Add(a_twsetupfilexfer.FileName.Get()); csv.Add("TWFF_" + a_twsetupfilexfer.Format); csv.Add(a_twsetupfilexfer.VRefNum.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
private static extern UInt16 MacosxDsmEntrySetupfilexfer ( ref TW_IDENTITY_MACOSX origin, ref TW_IDENTITY_MACOSX dest, DG dg, DAT dat, MSG msg, ref TW_SETUPFILEXFER twsetupfilexfer );
private static extern UInt16 Linux64DsmEntrySetupfilexfer ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_SETUPFILEXFER twsetupfilexfer );
private static extern UInt16 WindowsTwaindsmDsmEntrySetupfilexfer ( ref TW_IDENTITY_LEGACY origin, ref TW_IDENTITY_LEGACY dest, DG dg, DAT dat, MSG msg, ref TW_SETUPFILEXFER twsetupfilexfer );
/// <summary> /// Sets the file transfer information for the next file transfer. The application is responsible for /// verifying that the specified file name is valid and that the file either does not currently exist (in /// which case, the Source is to create the file), or that the existing file is available for opening and /// read/write operations. The application should also assure that the file format it is requesting /// can be provided by the Source /// </summary> /// <param name="setupFileXfer">The setup file xfer.</param> /// <returns></returns> public ReturnCode Set(ref TW_SETUPFILEXFER setupFileXfer) { return(DoIt(Message.Set, ref setupFileXfer)); }
/// <summary> /// Returns information for the default image or audio file. /// </summary> /// <param name="setupFileXfer">The setup file xfer.</param> /// <returns></returns> public ReturnCode GetDefault(ref TW_SETUPFILEXFER setupFileXfer) { return(DoIt(Message.GetDefault, ref setupFileXfer)); }