internal bool HandleWindowsMessage(ref MSG msg) { var handled = false; if (State > TwainState.S4) { // transform it into a pointer for twain IntPtr msgPtr = IntPtr.Zero; try { msgPtr = Config.MemoryManager.Allocate((uint)Marshal.SizeOf(msg)); IntPtr locked = Config.MemoryManager.Lock(msgPtr); Marshal.StructureToPtr(msg, locked, false); TW_EVENT evt = new TW_EVENT { pEvent = locked }; if (handled = DGControl.Event.ProcessEvent(ref evt) == ReturnCode.DSEvent) { Debug.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId}: {nameof(HandleWindowsMessage)} with {evt.TWMessage}"); HandleSourceMsg((Message)evt.TWMessage); } } finally { if (msgPtr != IntPtr.Zero) { Config.MemoryManager.Free(msgPtr); } } } return(handled); }
public static extern ReturnCode DsmWin32( [In, Out] TW_IDENTITY origin, [In, Out] TW_IDENTITY destination, DataGroups dg, DataArgumentType dat, Message msg, ref TW_EVENT data);
public ReturnCode ProcessEvent(ref TW_EVENT evt) { if (Is32Bit) { return(NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.Event, Message.ProcessEvent, ref evt)); } return(NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.Event, Message.ProcessEvent, ref evt)); }
/// <summary> /// Issue event commands... /// </summary> /// <param name="a_dg">Data group</param> /// <param name="a_msg">Operation</param> /// <param name="a_twevent">EVENT structure</param> /// <returns>TWAIN status</returns> public STS DatEvent(DG a_dg, MSG a_msg, ref TW_EVENT a_twevent) { STS sts; // Log it... if (Log.GetLevel() > 1) { Log.LogSendBefore(a_dg.ToString(), DAT.EVENT.ToString(), a_msg.ToString(), ""); } // Windows... if (ms_platform == Platform.WINDOWS) { // Issue the command... try { if (m_blUseLegacyDSM) { sts = (STS)WindowsTwain32DsmEntryEvent(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.EVENT, a_msg, ref a_twevent); } else { sts = (STS)WindowsTwaindsmDsmEntryEvent(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.EVENT, a_msg, ref a_twevent); } } 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)LinuxDsmEntryEvent(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.EVENT, a_msg, ref a_twevent); } else { sts = (STS)Linux64DsmEntryEvent(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.EVENT, a_msg, ref a_twevent); } } 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)MacosxDsmEntryEvent(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.EVENT, a_msg, ref a_twevent); } 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() > 1) { Log.LogSendAfter(sts.ToString(), ""); } // Check the event for anything interesting... if ((sts == STS.DSEVENT) || (sts == STS.NOTDSEVENT)) { ProcessEvent((MSG)a_twevent.TWMessage); } // All done... return (AutoDatStatus(sts)); }
private static extern UInt16 MacosxDsmEntryEvent ( ref TW_IDENTITY_MACOSX origin, ref TW_IDENTITY_MACOSX dest, DG dg, DAT dat, MSG msg, ref TW_EVENT twevent );
private static extern UInt16 Linux64DsmEntryEvent ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_EVENT twevent );
private static extern UInt16 WindowsTwaindsmDsmEntryEvent ( ref TW_IDENTITY_LEGACY origin, ref TW_IDENTITY_LEGACY dest, DG dg, DAT dat, MSG msg, ref TW_EVENT twevent );