public static extern ReturnCode DsmWin32(
     [In, Out] TW_IDENTITY origin,
     [In, Out] TW_IDENTITY destination,
     DataGroups dg,
     DataArgumentType dat,
     Message msg,
     ref TW_CALLBACK2 data);
Beispiel #2
0
        internal void RegisterCallback()
        {
            // TODO: support other platforms
            var callbackPtr = Marshal.GetFunctionPointerForDelegate(_callback32Delegate);

            // try new callback first
            var cb2 = new TW_CALLBACK2 {
                CallBackProc = callbackPtr
            };
            var rc = DGControl.Callback2.RegisterCallback(ref cb2);

            if (rc == ReturnCode.Success)
            {
                Debug.WriteLine("Registed Callback2 success.");
            }
            else
            {
                var status = GetStatus();
                Debug.WriteLine($"Register Callback2 failed with condition code: {status.ConditionCode}.");
            }


            if (rc != ReturnCode.Success)
            {
                // always register old callback
                var cb = new TW_CALLBACK {
                    CallBackProc = callbackPtr
                };

                rc = DGControl.Callback.RegisterCallback(ref cb);

                if (rc == ReturnCode.Success)
                {
                    Debug.WriteLine("Registed Callback success.");
                }
                else
                {
                    var status = GetStatus();
                    Debug.WriteLine($"Register Callback failed with {status.ConditionCode}.");
                }
            }
        }
Beispiel #3
0
        public ReturnCode RegisterCallback(ref TW_CALLBACK2 callback2)
        {
            if (Is32Bit)
            {
                if (IsWin)
                {
                    return(NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                  DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback2));
                }
                if (IsLinux)
                {
                    return(NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                    DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback2));
                }
                if (IsMac)
                {
                    return(NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32,
                                                  DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback2));
                }
            }

            if (IsWin)
            {
                return(NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32,
                                              DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback2));
            }
            if (IsLinux)
            {
                return(NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32,
                                                DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback2));
            }
            if (IsMac)
            {
                return(NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32,
                                              DataGroups.Control, DataArgumentType.Callback2, Message.RegisterCallback, ref callback2));
            }

            return(ReturnCode.Failure);
        }
Beispiel #4
0
        /// <summary>
        /// Convert the contents of a string to an callback2 structure...
        /// </summary>
        /// <param name="a_twcallback2">A TWAIN structure</param>
        /// <param name="a_szCallback2">A CSV string of the TWAIN structure</param>
        /// <returns>True if the conversion is successful</returns>
        public bool CsvToCallback2(ref TW_CALLBACK2 a_twcallback2, string a_szCallback2)
        {
            // Init stuff...
            a_twcallback2 = default(TW_CALLBACK2);

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

                // Grab the values...
                a_twcallback2.CallBackProc = (IntPtr)UInt64.Parse(asz[0]);
                a_twcallback2.RefCon = (UIntPtr)UInt64.Parse(asz[1]);
                a_twcallback2.Message = ushort.Parse(asz[2]);
            }
            catch
            {
                return (false);
            }

            // All done...
            return (true);
        }
Beispiel #5
0
 /// <summary>
 /// Convert the contents of a callback2 to a string that we can show in
 /// our simple GUI...
 /// </summary>
 /// <param name="a_twcallback2">A TWAIN structure</param>
 /// <returns>A CSV string of the TWAIN structure</returns>
 public string Callback2ToCsv(TW_CALLBACK2 a_twcallback2)
 {
     try
     {
         CSV csv = new CSV();
         csv.Add(a_twcallback2.CallBackProc.ToString());
         csv.Add(a_twcallback2.RefCon.ToString());
         csv.Add(a_twcallback2.Message.ToString());
         return (csv.Get());
     }
     catch
     {
         return ("***error***");
     }
 }
Beispiel #6
0
        /// <summary>
        /// Issue callback2 commands...
        /// </summary>
        /// <param name="a_dg">Data group</param>
        /// <param name="a_msg">Operation</param>
        /// <param name="a_twcallback2">Callback2 structure</param>
        /// <returns>TWAIN status</returns>
        public STS DatCallback2(DG a_dg, MSG a_msg, ref TW_CALLBACK2 a_twcallback2)
        {
            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.twcallback2 = a_twcallback2;
                    threaddata.dg = a_dg;
                    threaddata.msg = a_msg;
                    threaddata.dat = DAT.CALLBACK;
                    long lIndex = m_twaincommand.Submit(threaddata);

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

                    // Return the result...
                    a_twcallback2 = m_twaincommand.Get(lIndex).twcallback2;
                    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.CALLBACK2.ToString(), a_msg.ToString(), Callback2ToCsv(a_twcallback2));
            }

            // Windows...
            if (ms_platform == Platform.WINDOWS)
            {
                // Issue the command...
                try
                {
                    if (m_blUseLegacyDSM)
                    {
                        sts = (STS)WindowsTwain32DsmEntryCallback2(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.CALLBACK2, a_msg, ref a_twcallback2);
                    }
                    else
                    {
                        sts = (STS)WindowsTwaindsmDsmEntryCallback2(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.CALLBACK2, a_msg, ref a_twcallback2);
                    }
                }
                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)LinuxDsmEntryCallback2(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.CALLBACK2, a_msg, ref a_twcallback2);
                    }
                    else
                    {
                        sts = (STS)Linux64DsmEntryCallback2(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.CALLBACK2, a_msg, ref a_twcallback2);
                    }
                }
                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)MacosxDsmEntryCallback2(ref m_twidentitymacosxApp, IntPtr.Zero, a_dg, DAT.CALLBACK2, a_msg, ref a_twcallback2);
                }
                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(), Callback2ToCsv(a_twcallback2));
            }

            // All done...
            return (AutoDatStatus(sts));
        }
Beispiel #7
0
 private static extern UInt16 MacosxDsmEntryCallback2
 (
     ref TW_IDENTITY_MACOSX origin,
     IntPtr dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_CALLBACK2 twcallback
 );
Beispiel #8
0
 private static extern UInt16 Linux64DsmEntryCallback2
 (
     ref TW_IDENTITY origin,
     ref TW_IDENTITY dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_CALLBACK2 twcallback2
 );
Beispiel #9
0
 private static extern UInt16 WindowsTwaindsmDsmEntryCallback2
 (
     ref TW_IDENTITY_LEGACY origin,
     ref TW_IDENTITY_LEGACY dest,
     DG dg,
     DAT dat,
     MSG msg,
     ref TW_CALLBACK2 twcallback2
 );