1

I am writting some c# code for extract MICR string from checks.

My scanner is Cannon DR-850M which support MICR reader.

It can read MICR string on it's own scanning program. But I need to make my own by using TWAIN.

I can scan images in my program with TWAIN driver. However, I couldn't find how to get MICR string.

Is there a function to access scanner's MICR reader in TWAIN? or anything else?


I found that MICR data were located in "Extended Image Info". Thanks for answering.

and I got a little more problem.

Here's my code.

// Twain DLL Wrapper
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwInfo
{                                   // TW_INFO
    public short InfoID;
    public short ItemType;
    public short NumItems;
    public short CondCode;
    public int Item;
}

[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwExtImageInfo
{                                   // TW_EXTIMAGEINFO
    public int NumInfos;
    [MarshalAs(UnmanagedType.Struct, SizeConst = 1)]
    public TwInfo Info;
}

//Application
public void GetExtendedImageInfo()
    {
        TwRC rc;
        TwExtImageInfo exinf = new TwExtImageInfo();

        exinf.NumInfos = 1;
        exinf.Info = new TwInfo();
        exinf.Info.InfoID = (short)TwEI.BARCODETEXT;

        rc = DSexfer(appid, srcds, TwDG.Image, TwDAT.ExtImageInfo, TwMSG.Get, exinf);

        // Here's What I want to know.
        IntPtr itemPtr = new IntPtr(exinf.Info.Item);  
        string str = Marshal.PtrToStringAnsi(itemPtr); // It returns weird value.
    }

// Here's result
exinf.Info.CondCode : 0 (short)
exinf.Info.InfoID   : 4610 (short)
exinf.Info.Item : 36962876 (int)  // what's that?
exinf.Info.ItemType : 12 (short)
exinf.Info.NumItems : 4 (short)
exinf.NumInfos      : 1 (int)

I got these values from TWAIN.

But I don't know what kind of value exinf.Info.Item is

In sample App, It show right MICR characters. But my own returns strange value.

Can I get some help?

David Pyo
  • 97
  • 11
  • Don't put an answer to the question and add "solved" to its title. Post the answer below, in the section "your answer". Then accept it using the green tick to the left. – abatishchev Aug 25 '14 at 05:33

1 Answers1

1

SOLVED

I just missed using GlobalLock for pointer.

Here's code.

public string GetExtendedImageInfo()
    {
        TwRC rc;
        TwExtImageInfo exinf = new TwExtImageInfo();

        exinf.NumInfos = 1;
        exinf.Info = new TwInfo();
        exinf.Info.InfoID = (short)TwEI.BARCODETEXT;

        rc = DSexfer(appid, srcds, TwDG.Image, TwDAT.ExtImageInfo, TwMSG.Get, exinf);

        StringBuilder strItem = new StringBuilder(255);
        IntPtr itemPtr = new IntPtr(exinf.Info.Item);
        IntPtr dataPtr = GlobalLock(itemPtr);
        string str = Marshal.PtrToStringAnsi(dataPtr);
        GlobalUnlock(itemPtr);
        GlobalFree(itemPtr);

        return str;
    }
David Pyo
  • 97
  • 11