TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Not getting MSG_XFERREADY after calling MSG_ENABLEDS message

Forums › TWAIN Specification › TWAIN Specification Discussion › Not getting MSG_XFERREADY after calling MSG_ENABLEDS message

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • April 6, 2017 at 8:51 am #29899 Reply
    Srirangam Kadarkarai
    • Topics - 94
    • Replies - 183
    • Total Posts - 277

    Hi,
    I am using the below code to do the scanning. The below sequences are returning TWRC_SUCCESS.

    OpenDSM, OpenDS, EnableDS messages are returning success. But I am not receiving XFERREADY message in the ProcessMessage method. Can somebody help me to identify the cause for why XFERREADY message is received. For all the messages, I am getting NotDSEvent return code from PROCESSEVENT message.

    public partial class MainWindow : Window
    {
    TwainIdentity pOrigin;
    TwainIdentity pDest;
    TwainIdentity sourceDS;
    public MainWindow()
    {
    this.SourceInitialized += new EventHandler(MainWindow_SourceInitialized);
    }

    void MainWindow_SourceInitialized(object sender, EventArgs e)
    {
    IntPtr hWnd = new WindowInteropHelper(this).Handle;
    HwndSource hSource = HwndSource.FromHwnd(hWnd);
    hSource.AddHook(ProcessMessage);
    //throw new NotImplementedException();
    }

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC OpenDSM(ref TwainIdentity pOrigin, IntPtr zeroPtr, DG dGroup, DAT dType, MSG mgs, IntPtr scannerData);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC CloseDSM(ref TwainIdentity pOrigin, IntPtr zeroPtr, DG dGroup, DAT dType, MSG mgs, IntPtr scannerData);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwCC GetConditionCode(ref TwainIdentity pOrigin, IntPtr zeroPtr, DG dGroup, DAT dType, MSG mgs, ref TwStatus statusInfo);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC IsScannerAttached(ref TwainIdentity pOrigin, IntPtr zeroPtr, DG dGroup, DAT dType, MSG mgs, ref TwainIdentity scannerData);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC OpenDS(ref TwainIdentity pOrigin, IntPtr zeroPtr, DG dGroup, DAT dType, MSG mgs, ref TwainIdentity scannerData);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC CloseDS(ref TwainIdentity pOrigin, IntPtr zeroPtr, DG dGroup, DAT dType, MSG mgs, ref TwainIdentity scannerData);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwCC GetConditionCodeFromSource(ref TwainIdentity pOrigin, ref TwainIdentity pDest, DG dGroup, DAT dType, MSG mgs, ref TwStatus statusInfo);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC EnableDS(ref TwainIdentity pOrigin, ref TwainIdentity pDest, DG dGroup, DAT dType, MSG mgs, TwUserInterface twUserInterface);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC DisableDS(ref TwainIdentity pOrigin, ref TwainIdentity pDest, DG dGroup, DAT dType, MSG mgs, TwUserInterface twUserInterface);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC SelectScanner(ref TwainIdentity pOrigin, IntPtr zeroPtr, DG dGroup, DAT dType, MSG mgs, ref TwainIdentity selectedScannerData);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC ProcessEvent(ref TwainIdentity pOrigin, ref TwainIdentity pDest, DG dGroup, DAT dType, MSG mgs, ref TwEvent eventData);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    public static extern TwRC TransferImage(ref TwainIdentity pOrigin, ref TwainIdentity pDest, DG dGroup, DAT dType, MSG mgs, ref IntPtr imageData);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    private static extern TwRC SetDScapability(ref TwainIdentity pOrigin, ref TwainIdentity pDest, DG dg, DAT dat, MSG msg, TwCapability capability);

    [DllImport(“TWAINDSM.dll”, EntryPoint = “#1”)]
    private static extern TwRC RegisterDSCallBack(ref TwainIdentity pOrigin, ref TwainIdentity pDest, DG dg, DAT dat, MSG msg, ref TwCallback callBack);

    [DllImport(“user32.dll”, ExactSpelling = true)]
    private static extern int GetMessagePos();
    [DllImport(“user32.dll”, ExactSpelling = true)]
    private static extern int GetMessageTime();

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
    OpenDataSourceManager();
    }
    public bool OpenDataSourceManager()
    {
    IntPtr hWnd = new WindowInteropHelper(this).Handle;
    try
    {
    const short CountryUSA = 1;
    const short LanguageUSA = 13;

    pOrigin = new TwainIdentity();
    pOrigin.Id = IntPtr.Zero;
    pOrigin.Version.MajorNum = 1;
    pOrigin.Version.MinorNum = 1;
    pOrigin.Version.Language = LanguageUSA;
    pOrigin.Version.Country = CountryUSA;
    pOrigin.Version.Info = “Hack 1”;
    pOrigin.ProtocolMajor = (ushort)TwProtocol.Major;
    pOrigin.ProtocolMinor = (ushort)TwProtocol.Minor;
    pOrigin.SupportedGroups = (int)(DG.IMAGE | DG.CONTROL);
    pOrigin.Manufacturer = “NETMaster”;
    pOrigin.ProductFamily = “Freeware”;
    pOrigin.ProductName = “Hack”;

    pDest = new TwainIdentity();
    pOrigin.Version.MajorNum = 4;
    pOrigin.Version.MinorNum = 1;

    sourceDS = new TwainIdentity();
    pOrigin.Version.MajorNum = 4;
    pOrigin.Version.MinorNum = 1;

    TwainIdentity selectedScanner = new TwainIdentity();
    pOrigin.Version.MajorNum = 4;
    pOrigin.Version.MinorNum = 1;

    // OPENDSM is success
    TwRC retCode = OpenDSM(ref pOrigin, IntPtr.Zero, DG.CONTROL, DAT.PARENT, MSG.OPENDSM, hWnd);

    if (retCode == TwRC.Success && pOrigin.Id != IntPtr.Zero)
    {
    // OPENDS is success
    retCode = OpenDS(ref pOrigin, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, MSG.OPENDS, ref sourceDS);

    TwUserInterface twUI = new TwUserInterface();
    twUI.ShowUI = 0;
    twUI.ModalUI = 0;
    twUI.ParentHand = hWnd;

    // ENABLEDS is success
    retCode = EnableDS(ref pOrigin, ref sourceDS, DG.CONTROL, DAT.USERINTERFACE, MSG.ENABLEDS, twUI);

    // MessageBox.Show(sourceDS.ProductName);
    }
    else
    {
    TwStatus statusInfo = new TwStatus();
    TwCC conditionCode = GetConditionCode(ref pOrigin, IntPtr.Zero, DG.CONTROL, DAT.STATUS, MSG.GET, ref statusInfo);
    }

    }
    catch
    {
    }
    finally
    {
    //TwUserInterface twUI = new TwUserInterface();
    //twUI.ShowUI = 0;
    //twUI.ModalUI = 0;
    //twUI.ParentHand = hWnd;
    //TwRC retCode = DisableDS(ref pOrigin, ref sourceDS, DG.CONTROL, DAT.USERINTERFACE, MSG.DISABLEDS, twUI);
    //retCode = CloseDS(ref pOrigin, IntPtr.Zero, DG.CONTROL, DAT.IDENTITY, MSG.CLOSEDS, ref sourceDS);
    //retCode = CloseDSM(ref pOrigin, IntPtr.Zero, DG.CONTROL, DAT.PARENT, MSG.CLOSEDSM, hWnd);
    //if (retCode == TwRC.Success)
    // pOrigin.Id = IntPtr.Zero;
    }
    return true;
    }

    private IntPtr ProcessMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
    if (sourceDS.Id == IntPtr.Zero)
    {
    handled = false;
    return IntPtr.Zero;
    }
    WinMsg winMessage = new WinMsg();
    winMessage.hwnd = hwnd;
    winMessage.message = msg;
    winMessage.wParam = wParam;
    winMessage.lParam = lParam;
    winMessage.time = GetMessageTime();
    int pos = GetMessagePos();
    winMessage.x = (short)pos;
    winMessage.y = (short)(pos >> 16);
    TwEvent eventMsg = new TwEvent();
    eventMsg.EventPtr = Marshal.AllocHGlobal(Marshal.SizeOf(winMessage));

    Marshal.StructureToPtr(winMessage, eventMsg.EventPtr, false);
    TwRC retCode = ProcessEvent(ref pOrigin, ref sourceDS, DG.CONTROL, DAT.EVENT, MSG.PROCESSEVENT, ref eventMsg);

    if (retCode == TwRC.Failure)
    {
    //TwStatus statusInfo = new TwStatus();
    //TwCC conditionCode = GetConditionCodeFromSource(ref pOrigin, ref sourceDS, DG.CONTROL, DAT.STATUS, MSG.GET, ref statusInfo);
    }
    if (retCode == TwRC.NotDSEvent)
    {
    handled = false;
    return IntPtr.Zero;
    }
    else if (retCode == TwRC.DSEvent)
    {
    if(eventMsg.Message == (short)MSG.XFERREADY)
    {
    IntPtr bitmap = IntPtr.Zero;
    retCode = TransferImage(ref pOrigin, ref pDest, DG.IMAGE, DAT.IMAGENATIVEXFER, MSG.GET, ref bitmap);
    }
    }

    return IntPtr.Zero;
    }
    }

  • Author
    Posts
Viewing 1 post (of 1 total)
Reply To: Not getting MSG_XFERREADY after calling MSG_ENABLEDS message
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • Girls of Desire: All babes in one place, crazy, art
  • EPSON V600 TWAIN and WIA on Windows 10
  • When and how to use WaitForEvents command ?
  • Problem enumerating list of installed scanners in windows server 2012
  • Failed to create TWAIN progress! Error code is 1260.
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.