public static extern ReturnCode DsmWin32( [In, Out] TW_IDENTITY origin, [In, Out] TW_IDENTITY destination, DataGroups dg, DataArgumentType dat, Message msg, ref TW_STATUSUTF8 data);
public ReturnCode Get(ref TW_STATUS status, DataSource source, out string message) { message = null; var rc = ReturnCode.Failure; TW_STATUSUTF8 real = new TW_STATUSUTF8 { Status = status }; if (Is32Bit) { if (IsWin) { rc = NativeMethods.DsmWin32(Session.Config.App32, source?.Identity32, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get, ref real); } else if (IsLinux) { rc = NativeMethods.DsmLinux32(Session.Config.App32, source?.Identity32, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get, ref real); } else if (IsMac) { rc = NativeMethods.DsmMac32(Session.Config.App32, source?.Identity32, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get, ref real); } } else { if (IsWin) { rc = NativeMethods.DsmWin64(Session.Config.App32, source?.Identity32, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get, ref real); } else if (IsLinux) { rc = NativeMethods.DsmLinux64(Session.Config.App32, source?.Identity32, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get, ref real); } else if (IsMac) { rc = NativeMethods.DsmMac64(Session.Config.App32, source?.Identity32, DataGroups.Control, DataArgumentType.StatusUtf8, Message.Get, ref real); } } if (rc == ReturnCode.Success) { message = ReadUtf8String(ref real); } return(rc); }
private string ReadUtf8String(ref TW_STATUSUTF8 status) { if (status.UTF8string != IntPtr.Zero) { try { IntPtr lockedPtr = Session.Config.MemoryManager.Lock(status.UTF8string); var buffer = new byte[status.Size - 1]; Marshal.Copy(lockedPtr, buffer, 0, buffer.Length); return(Encoding.UTF8.GetString(buffer)); } finally { Session.Config.MemoryManager.Unlock(status.UTF8string); Session.Config.MemoryManager.Free(status.UTF8string); } } return(null); }
/// <summary> /// Get some text for an error... /// </summary> /// <param name="a_dg">Data group</param> /// <param name="a_msg">Operation</param> /// <param name="a_twstatusutf8">STATUSUTF8 structure</param> /// <returns>TWAIN status</returns> public STS DatStatusutf8(DG a_dg, MSG a_msg, ref TW_STATUSUTF8 a_twstatusutf8) { 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.twstatusutf8 = a_twstatusutf8; threaddata.dg = a_dg; threaddata.msg = a_msg; threaddata.dat = DAT.STATUSUTF8; long lIndex = m_twaincommand.Submit(threaddata); // Submit the command and wait for the reply... CallerToThreadSet(); ThreadToCallerWaitOne(); // Return the result... a_twstatusutf8 = m_twaincommand.Get(lIndex).twstatusutf8; 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.STATUSUTF8.ToString(), a_msg.ToString(), ""); } // Windows... if (ms_platform == Platform.WINDOWS) { // Issue the command... try { if (m_blUseLegacyDSM) { sts = (STS)WindowsTwain32DsmEntryStatusutf8(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.STATUSUTF8, a_msg, ref a_twstatusutf8); } else { sts = (STS)WindowsTwaindsmDsmEntryStatusutf8(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.STATUSUTF8, a_msg, ref a_twstatusutf8); } } 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)LinuxDsmEntryStatusutf8(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.STATUSUTF8, a_msg, ref a_twstatusutf8); } else { sts = (STS)Linux64DsmEntryStatusutf8(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.STATUSUTF8, a_msg, ref a_twstatusutf8); } } 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)MacosxDsmEntryStatusutf8(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.STATUSUTF8, a_msg, ref a_twstatusutf8); } 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(), ""); } // All done... return (AutoDatStatus(sts)); }
private static extern UInt16 MacosxDsmEntryStatusutf8 ( ref TW_IDENTITY_MACOSX origin, ref TW_IDENTITY_MACOSX dest, DG dg, DAT dat, MSG msg, ref TW_STATUSUTF8 twstatusutf8 );
private static extern UInt16 Linux64DsmEntryStatusutf8 ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_STATUSUTF8 twstatusutf8 );
private static extern UInt16 WindowsTwaindsmDsmEntryStatusutf8 ( ref TW_IDENTITY_LEGACY origin, ref TW_IDENTITY_LEGACY dest, DG dg, DAT dat, MSG msg, ref TW_STATUSUTF8 twstatusutf8 );