Here is my code,For reference
public string ProcessDocument()
{
string Output = string.Empty;
int Count = 2;
string[] strData = null;
try
{
int nRet = -1;
string strLog;
string strTmp;
MessageBox.Show("ProcessInit Start");
ProcessInit();
MessageBox.Show("SetupOptions Start");
nRet = SetupOptions();
if (nRet != MICR_ST_OK)
{
strLog = "Setup Options FAILED...";
MessageBox.Show(strLog);
}
else
{
strLog = "Setup Options SUCCESS...";
MessageBox.Show(strLog);
StringBuilder strResponse = new StringBuilder();
strResponse.Capacity = 8192;
int nResponseLength = 8192;
m_strDocInfo = "";
nRet = MTMICRProcessCheck(m_strCurrentDeviceName, m_strOptions, strResponse, ref nResponseLength);
if (nRet == MICR_ST_OK)
{
m_strDocInfo = strResponse.ToString();
Output = m_strDocInfo;
nRet = MTMICRGetValue(m_strDocInfo, "CommandStatus", "ReturnCode", strResponse, ref nResponseLength);
strTmp = strResponse.ToString();
#region Front Image
int nReti;
StringBuilder strResponsei = new StringBuilder();
strResponsei.Capacity = 4096;
int nResponseLengthi = 4096;
int nImageSize;
string strTmpi;
string strImageID;
nReti = MTMICRGetIndexValue(m_strDocInfo, "ImageInfo", "ImageSize", 1, strResponsei, ref nResponseLengthi);
strTmpi = strResponsei.ToString();
nImageSize = Convert.ToInt32(strTmpi);
if (nImageSize > 0)
{
nReti = MTMICRGetIndexValue(m_strDocInfo, "ImageInfo", "ImageURL", 1, strResponsei, ref nResponseLengthi);
strImageID = strResponsei.ToString();
strLog = "Image size =" + nImageSize + "ImageID = " + strImageID;
byte[] imageBuf = new byte[nImageSize];
nRet = MTMICRGetImage(m_strCurrentDeviceName, strImageID, imageBuf, ref nImageSize);
if (nRet == MICR_ST_OK)
{
System.IO.FileStream fileWriter = new System.IO.FileStream(@"c:\test.jpg", System.IO.FileMode.Create);
fileWriter.Write(imageBuf, 0, imageBuf.Length);
image_Buf = imageBuf;
fileWriter.Close();
int nActualSize = nImageSize;
string strImageFile = g_strAppPath + "\\docimage" + ++nTotalDocProcessed + ".jpg";
int hFile = -1;
hFile = CreateFile(strImageFile, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile > 0)
{
strLog = "NumOfBytes to write =" + nActualSize;
IntPtr pOverlapped = IntPtr.Zero;
bool bRet = WriteFile(hFile, imageBuf, nImageSize, ref nActualSize, pOverlapped);
}
}
}
#endregion
#region Back Image
int nRetb;
StringBuilder strResponseb = new StringBuilder();
strResponseb.Capacity = 4096;
int nResponseLengthb = 4096;
int nImageSizeb;
string strTmpb;
string strImageIDb;
nRetb = MTMICRGetIndexValue(m_strDocInfo, "ImageInfo", "ImageSize", 2, strResponseb, ref nResponseLengthb);
strTmpb = strResponseb.ToString();
nImageSizeb = Convert.ToInt32(strTmpb);
if (nImageSizeb > 0)
{
nRetb = MTMICRGetIndexValue(m_strDocInfo, "ImageInfo", "ImageURL", 2, strResponseb, ref nResponseLengthb);
strImageIDb = strResponseb.ToString();
strLog = "B Image size =" + nImageSizeb + "B ImageID = " + strImageIDb;
byte[] imageBuf = new byte[nImageSizeb];
nRet = MTMICRGetImage(m_strCurrentDeviceName, strImageIDb, imageBuf, ref nImageSizeb);
if (nRet == MICR_ST_OK)
{
System.IO.FileStream fileWriter = new System.IO.FileStream(@"c:\test_b.jpg", System.IO.FileMode.Create);
fileWriter.Write(imageBuf, 0, imageBuf.Length);
image_Buf_B = imageBuf;
fileWriter.Close();
int nActualSize = nImageSizeb;
string strImageFile = g_strAppPath + "\\docimage" + ++nTotalDocProcessed + ".jpg";
int hFile = -1;
hFile = CreateFile(strImageFile, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (hFile > 0)
{
strLog = "B NumOfBytes to write =" + nActualSize;
IntPtr pOverlapped = IntPtr.Zero;
bool bRet = WriteFile(hFile, imageBuf, nImageSizeb, ref nActualSize, pOverlapped);
}
}
}
#endregion
}
else
{
strLog = "MTMICRProcessCheck return code " + Convert.ToString(nRet);
MessageBox.Show(strLog);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + " Line Number " + ex.StackTrace);
}
finally
{
if (m_bDeviceOpened)
CloseCurrentDevice();
}
return Output;
}