Exemplo n.º 1
0
 public static extern ReturnCode DsmWin32(
     [In, Out] TW_IDENTITY origin,
     [In, Out] TW_IDENTITY destination,
     DataGroups dg,
     DataArgumentType dat,
     Message msg,
     ref TW_CUSTOMDSDATA data);
Exemplo n.º 2
0
        ReturnCode DoIt(Message msg, ref TW_CUSTOMDSDATA data)
        {
            if (Is32Bit)
            {
                if (IsWin)
                {
                    return(NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                  DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data));
                }
                if (IsLinux)
                {
                    return(NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                    DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data));
                }
                if (IsMac)
                {
                    return(NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                  DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data));
                }
            }

            if (IsWin)
            {
                return(NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
                                              DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data));
            }
            if (IsLinux)
            {
                return(NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
                                                DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data));
            }
            if (IsMac)
            {
                return(NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
                                              DataGroups.Control, DataArgumentType.CustomDSData, msg, ref data));
            }

            return(ReturnCode.Failure);
        }
Exemplo n.º 3
0
 public ReturnCode Set(ref TW_CUSTOMDSDATA data)
 {
     return(DoIt(Message.Set, ref data));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get/Set the custom DS data...
        /// </summary>
        /// <param name="a_dg">Data group</param>
        /// <param name="a_msg">Operation</param>
        /// <param name="a_twcustomdsdata">CUSTOMDSDATA structure</param>
        /// <returns>TWAIN status</returns>
        public STS DatCustomdsdata(DG a_dg, MSG a_msg, ref TW_CUSTOMDSDATA a_twcustomdsdata)
        {
            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.twcustomdsdata = a_twcustomdsdata;
                    threaddata.dg = a_dg;
                    threaddata.msg = a_msg;
                    threaddata.dat = DAT.CUSTOMDSDATA;
                    long lIndex = m_twaincommand.Submit(threaddata);

                    // Submit the command and wait for the reply...
                    CallerToThreadSet();
                    ThreadToCallerWaitOne();

                    // Return the result...
                    a_twcustomdsdata = m_twaincommand.Get(lIndex).twcustomdsdata;
                    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.CUSTOMDSDATA.ToString(), a_msg.ToString(), CustomdsdataToCsv(a_twcustomdsdata));
            }

            // Windows...
            if (ms_platform == Platform.WINDOWS)
            {
                // Issue the command...
                try
                {
                    if (m_blUseLegacyDSM)
                    {
                        sts = (STS)WindowsTwain32DsmEntryCustomdsdata(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.CUSTOMDSDATA, a_msg, ref a_twcustomdsdata);
                    }
                    else
                    {
                        sts = (STS)WindowsTwaindsmDsmEntryCustomdsdata(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.CUSTOMDSDATA, a_msg, ref a_twcustomdsdata);
                    }
                }
                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)LinuxDsmEntryCustomdsdata(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.CUSTOMDSDATA, a_msg, ref a_twcustomdsdata);
                    }
                    else
                    {
                        sts = (STS)Linux64DsmEntryCustomdsdata(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.CUSTOMDSDATA, a_msg, ref a_twcustomdsdata);
                    }
                }
                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)MacosxDsmEntryCustomdsdata(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.CUSTOMDSDATA, a_msg, ref a_twcustomdsdata);
                }
                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(), CustomdsdataToCsv(a_twcustomdsdata));
            }

            // All done...
            return (AutoDatStatus(sts));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Convert the contents of a string to a custom DS data structure...
        /// </summary>
        /// <param name="a_twcustomdsdata">A TWAIN structure</param>
        /// <param name="a_szCustomdsdata">A CSV string of the TWAIN structure</param>
        /// <returns>True if the conversion is successful</returns>
        public bool CsvToCustomdsdata(ref TW_CUSTOMDSDATA a_twcustomdsdata, string a_szCustomdsdata)
        {
            // Init stuff...
            a_twcustomdsdata = default(TW_CUSTOMDSDATA);

            // Build the string...
            try
            {
                string[] asz = CSV.Parse(a_szCustomdsdata);

                // Grab the values...
                a_twcustomdsdata.InfoLength = uint.Parse(asz[0]);
                a_twcustomdsdata.hData = DsmMemAlloc(a_twcustomdsdata.InfoLength);
                IntPtr intptr = DsmMemLock(a_twcustomdsdata.hData);
                byte[] bProfile = new byte[a_twcustomdsdata.InfoLength];
                Marshal.Copy((IntPtr)UInt64.Parse(asz[1]), bProfile, 0, (int)a_twcustomdsdata.InfoLength);
                Marshal.Copy(bProfile, 0, intptr, (int)a_twcustomdsdata.InfoLength);
                DsmMemUnlock(a_twcustomdsdata.hData);
            }
            catch
            {
                return (false);
            }

            // All done...
            return (true);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Convert the contents of a custom DS data to a string that we can show in
 /// our simple GUI...
 /// </summary>
 /// <param name="a_twcustomdsdata">A TWAIN structure</param>
 /// <returns>A CSV string of the TWAIN structure</returns>
 public string CustomdsdataToCsv(TW_CUSTOMDSDATA a_twcustomdsdata)
 {
     try
     {
         CSV csv = new CSV();
         csv.Add(a_twcustomdsdata.InfoLength.ToString());
         IntPtr intptr = DsmMemLock(a_twcustomdsdata.hData);
         csv.Add(intptr.ToString());
         DsmMemUnlock(a_twcustomdsdata.hData);
         return (csv.Get());
     }
     catch
     {
         return ("***error***");
     }
 }
Exemplo n.º 7
0
 private static extern UInt16 MacosxDsmEntryCustomdsdata
 (
     ref TW_IDENTITY_MACOSX origin,
     ref TW_IDENTITY_MACOSX dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_CUSTOMDSDATA twcustomedsdata
 );
Exemplo n.º 8
0
 private static extern UInt16 Linux64DsmEntryCustomdsdata
 (
     ref TW_IDENTITY origin,
     ref TW_IDENTITY dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_CUSTOMDSDATA twcustomdsdata
 );
Exemplo n.º 9
0
 private static extern UInt16 WindowsTwaindsmDsmEntryCustomdsdata
 (
     ref TW_IDENTITY_LEGACY origin,
     ref TW_IDENTITY_LEGACY dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_CUSTOMDSDATA twcustomdsdata
 );