Home › Forums › TWAIN Classic › Simple TWAIN app question – reverse the process › Re: polling ICAP_FEEDERLOADED
Hi eramgarden – I’d like to help, but the library you are using from CodeProject is kind of a hack – minimal comments, and almost everything done in-line. So for example there is no ‘Open the scanner’ function, nor are there the basic functions you need for reading capabilities. So I hope I’m getting this right…
The code that opens the scanner appears inside the Acquire method, here is one version I found, this is just the actual ‘open the scanner’ call:
rc = DSMident( appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds );
if( rc != TwRC.Success )
return;
If successful, that call will open the default TWAIN device.
Note that it depends on previous code that initializes the various variables like srcds and appid.
You’ll need to add this definition to the enum TwCap:
CAP_FEEDERLOADED = 0x1003
Once the scanner is in the open state, you could call
// create a capability structure with the capability code:
TwCapability cap = new TwCapability(TwCap.CAP_FEEDERLOADED);
// query the scanner for the current value of the capability:
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Get, cap);
if( rc != TWRC.Success ) {
// something's wrong
CloseSrc();
return;
}
// Dig out the returned value of the capability.
// I'm going to ASSUME the returned container has
// ConType==TwOn.One.
// and contains a TWTY_BOOL value.
// Lock the container handle to get a pointer to its contents:
IntPtr pv = Twain.GlobalLock( cap.Handle );
// Read the 32-bit value of the container, it
// follows a 2-byte ItemType field in the container:
bool bFeederLoaded = ( 0 != (short)Marshal.ReadInt32( pv, 2 ) );
Twain.GlobalUnlock( cap.Handle );
Twain.GlobalFree( cap.Handle );