Home › Forums › TWAIN Specification › TWAIN Specification Discussion › Not getting MSG_XFERREADY after calling MSG_ENABLEDS message
- This topic is empty.
- AuthorPosts
- Srirangam Kadarkarai
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;
}
} - AuthorPosts