Hmm - the code you've placed this above is in VB where as the code I gave is in C#. The code needs to be placed in TwainLib.cs under the "public void Aquire". To make it easy I've added the whole of my copy of the void below:
public void Acquire()
{
TwRC rc;
CloseSrc();
if( appid.Id == IntPtr.Zero )
{
Init( hwnd );
if( appid.Id == IntPtr.Zero )
return;
}
rc = DSMident( appid, IntPtr.Zero, TwDG.Control, TwDAT.Identity, TwMSG.OpenDS, srcds );
if( rc != TwRC.Success )
return;
TwCapability cap = new TwCapability( TwCap.XferCount, -1 );
rc = DScap( appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap );
if( rc != TwRC.Success )
{
CloseSrc();
return;
}
TwCapability capDuplex = new TwCapability(TwCap.CAP_DUPLEXENABLED, 0, TwType.Bool);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capDuplex);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capResX = new TwCapability(TwCap.CAP_RESX, 150, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResX);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capResY = new TwCapability(TwCap.CAP_RESY, 150, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResY);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capPixelType = new TwCapability(TwCap.IPixelType, 0);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capPixelType);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capPaperSize = new TwCapability(TwCap.ICAP_SUPPORTEDSIZES, 1);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capPaperSize);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capAutoDeskew = new TwCapability(TwCap.ICAP_AUTOMATICDESKEW, 1, TwType.Bool);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capAutoDeskew);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capAutoScan = new TwCapability(TwCap.CAP_AUTOSCAN, 1, TwType.Bool);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capAutoScan);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capThreshold = new TwCapability(TwCap.ICAP_THRESHOLD, 100, TwType.Fix32 );
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capThreshold);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capBrightness = new TwCapability(TwCap.ICAP_BRIGHTNESS, 400, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capBrightness);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capGamma = new TwCapability(TwCap.ICAP_GAMMA, 2, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capGamma);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwCapability capHalfTones = new TwCapability(TwCap.ICAP_HALFTONES, "TextEnhancement Technology");
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capHalfTones);
if (rc != TwRC.Success)
{
CloseSrc();
return;
}
TwUserInterface guif = new TwUserInterface();
guif.ShowUI = 0;
guif.ModalUI = 1;
guif.ParentHand = hwnd;
rc = DSuserif( appid, srcds, TwDG.Control, TwDAT.UserInterface, TwMSG.EnableDS, guif );
if( rc != TwRC.Success )
{
CloseSrc();
return;
}
}
You then need to update the TwainDef.cs file and replace the "internal enum TwCap : short" with the following (the bits commented // DOESN'T WORK are just commands that my particular scanner wouldn't support):
internal enum TwCap : short
{
XferCount = 0x0001,
ICompression = 0x0100,
IPixelType = 0x0101,
IUnits = 0x0102,
IXferMech = 0x0103,
CAP_DUPLEXENABLED = 0x1013,
CAP_RESX = 0x1118,
CAP_RESY = 0x1119,
ICAP_SUPPORTEDSIZES = 0x1122,
ICAP_AUTOMATICDESKEW = 0x1151,
ICAP_AUTOMATICROTATE = 0x1152,
ICAP_AUTODISCARDBLANKPAGES = 0x1134,
ICAP_NOISEFILTER = 0x1148,
ICAP_AUTOBRIGHT = 0x1100,
CAP_AUTOSCAN = 0x1010,
ICAP_THRESHOLD = 0x1123,
ICAP_BRIGHTNESS = 0x1101,
ICAP_GAMMA = 0x1108,
ICAP_HALFTONES = 0x1109,
ICAP_PIXELFLAVOR = 0x111F
}
Then also in the TwainDef.cs near the bottom you'll find this:
public TwCapability(TwCap cap, string sval)
{
Cap = (short)cap;
ConType = (short)TwOn.One;
Handle = Twain.GlobalAlloc(0x42, 6);
IntPtr pv = Twain.GlobalLock(Handle);
Marshal.WriteInt16(pv, 0, (short)TwType.Str32);
Marshal.StringToHGlobalUni(sval);
Twain.GlobalUnlock(Handle);
}
Underneath this stick the following code in:
public TwCapability(TwCap cap, short sval, TwType TheType)
{
Cap = (short)cap;
ConType = (short)TwOn.One;
Handle = Twain.GlobalAlloc(0x42, 6);
IntPtr pv = Twain.GlobalLock(Handle);
if (TheType == TwType.Bool)
{
Marshal.WriteInt16(pv, 0, (short)TwType.Bool);
}
if (TheType == TwType.Fix32)
{
Marshal.WriteInt16(pv, 0, (short)TwType.Fix32);
}
Marshal.WriteInt32(pv, 2, (int)sval);
Twain.GlobalUnlock(Handle);
}
It should all work then
|