Code: Select all
#GdTwain Log Start. Version: 651
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
Start: UnloadSourceManager.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
End: UnloadSourceManager.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
Start: OpenSourceManager.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
DSM 32-bit library loaded: C:\Windows\TWAIN_32.DLL
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
Entry point of the DSM found.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
End: OpenSourceManager.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 3
-------------------
Start: OpenSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 3
-------------------
GDTWAIN_Mgr: Start Getting DAT_STATUS
RC: TWRC_FAILURE
CC: TWCC_SUCCESS
State: 3
-------------------
GDTWAIN_Mgr: End Getting DAT_STATUS
RC: TWRC_FAILURE
CC: TWCC_OPERATIONERROR
State: 3
-------------------
End: OpenSource.
RC: TWRC_FAILURE
CC: TWCC_OPERATIONERROR
State: 3
-------------------
#GdTwain Log Stop.
My code up to that point looks like this:
Code: Select all
bool opened;
TwainStatus status = gdi.TwainGetState();
Debug.WriteLine("Initial status: "+status.ToString());
bool ok = gdi.TwainCloseSource();
Debug.WriteLine("Closing: " + ((ok) ? "OK" : "Failed"));
String defSource = gdi.TwainGetDefaultSourceName(Handle);
Debug.WriteLine("Default source: \"" + defSource + "\"");
Debug.WriteLine("Requested source: \"" + source + "\"");
if (source != "?")
opened = (source == defSource)
? gdi.TwainOpenDefaultSource(Handle)
: gdi.TwainOpenSource(Handle, source);
else
{
if (!gdi.TwainSelectSource(Handle))
return -3;
opened = gdi.TwainOpenDefaultSource(Handle);
}
if (!opened)
{
Debug.WriteLine("Failed to open!");
TwainResultCode rc = gdi.TwainGetLastResultCode();
if (rc != TwainResultCode.TWRC_SUCCESS)
{
TwainConditionCode cc = gdi.TwainGetLastConditionCode();
---->>> MessageBox.Show("ResultCode = " + rc.ToString() + "\nConditionCode = " + cc.ToString(), "TwainOpenDefaultSource");
}
return -2;
}
status = gdi.TwainGetState();
Debug.WriteLine("Post-open status: " + status.ToString());
if (status < TwainStatus.TWAIN_SOURCE_OPEN)
{
gdi.TwainOpenSource(Handle, source);
status = gdi.TwainGetState();
Debug.WriteLine("Post-post-open status: " + status.ToString());
if (status < TwainStatus.TWAIN_SOURCE_OPEN)
return -1;
}
ResultCode = TWRC_FAILURE
ConditionCode = TWCC_OPERATIONERROR
My DebugOutput is as follows:
First time:
Initial status: TWAIN_PRESESSION
Closing: OK
Default source: "WIA-CanoScan 4400F"
Requested source: "CanoScan 4400F"
Failed to open!
Subsequent times in same session:
Initial status: TWAIN_SM_OPEN
Closing: OK
Default source: "WIA-CanoScan 4400F"
Requested source: "CanoScan 4400F"
Failed to open!
From the log file, it appears that there's a problem with obtaining DAT_STATUS. Is this really necessary for proper functioning, and if not, can I somehow disable this step?
Also, if I use the WIA driver (which I'd rather not - you can't control the parameters such as dpi and colours via the TWAIN interface for this WIA driver), I get a "Server busy" message box (with buttons "Switch to" and "Retry") as soon as I try to do anything with the WIA driver, such as starting a preview, performing the scan or adjusting the scanning parameters, and it is very hard to get rid of this dialog and make the scan begin.
Running Windows 7 64-bit SP1 with a 32-bit C# program, .NET 2.0, compiled using Visual Studio 2008.