Home › Forums › TWAIN Classic › Can only get scan to work once if cancelled
- This topic has 6 replies, 2 voices, and was last updated 18 years, 3 months ago by Anonymous.
- AuthorPosts
Can anyone tell me why when using the code below, original code from post of
Johnathan Arnold that when i click the button to call the below function
everyting works great captures image, saves it to jpg format etc, but it
only lets me do it once and to do it again i have to restart the
application.. i also have the same problem if i click cancel to the actual
scanner control form that fires up when it works if i click the button again
nothing happens, restart app and bobs your uncle.Original code from:
http://www.buddydog.org/C++Builder/c++builder.htmlvoid __fastcall TMainForm::IMG1AquireClick(TObject *Sender)
{
AnsiString tmp_picpath;
HANDLE dib;
LPBITMAPINFO bmi;
if(TwainExists())
{
dib = TwainGetImage(IMG1Aquire->Handle);
if ( dib == 0 )
{
return;
}
bmi = (LPBITMAPINFO)::GlobalLock(dib);TwainImage->Picture->Bitmap->Height = bmi->bmiHeader.biHeight;
TwainImage->Picture->Bitmap->Width = bmi->bmiHeader.biWidth;
SetDIBits( TwainImage->Picture->Bitmap->Canvas->Handle,
TwainImage->Picture->Bitmap->Handle, 0,
(UINT) bmi->bmiHeader.biHeight,
(Byte*)((Byte*)bmi + sizeof(BITMAPINFOHEADER)),
bmi, DIB_RGB_COLORS );
::GlobalUnlock( dib );
::GlobalFree( dib );
tmp_picpath = session.session_img_path+EpocFromNow()+”.jpg”;
if(Bitmap2Jpg(TwainImage->Picture->Bitmap,tmp_picpath))
IMG1->Text = tmp_picpath;
else
ShowMessage(“Problem converting image.”);
}
else
ShowMessage(“No devices found.”);
}
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
extern HANDLE TwainInst;
FreeLibrary( TwainInst );
}You’ve said little about what error message, if any, you get when you try and capture a 2nd image, and nothing about the device. Both would be helpful in deciding whether code or device is at fault. I have encountered scanners that only allow a single image to be transferred programmatically before the DS has to be closed and re-opened. The DS isn’t Xerox Scan Manager Pro, is it ❓
AndyI haven’t got enough coding in there to give me the correct error code but if i think it is where you mentioned closing and then reopening the DS when selecting cancel as if i tell it to goto exit when ( !TwainOpenDefaultSource() ) it allows me to open it again, but then another devive where the exception throws up an error code 4 freezes the app if i click getimage again..
I will be as clear as I can:
– please quote any error message(s)
– please tell us what device you are using
I am going to have to merge some code into it then to get some error codes out of it as i am using Jonathan Arnold’s code to test adn it returns no errors, i think it is returning TWCC_BADCAP when i click cancel on my WIA-e+ 48U 1.0 flatbed scanner instead of going through the preview or scan image but like i said i’ll have to merge some code or find some that has more testing within it..
I do think its what you said though where the DS needs shutting down and restarting if the action above is carried out.
@Anonymous wrote:
I am going to have to merge some code into it then to get some error codes out of it as i am using Jonathan Arnold’s code to test adn it returns no errors, i think it is returning TWCC_BADCAP when i click cancel on my WIA-e+ 48U 1.0 flatbed scanner instead of going through the preview or scan image but like i said i’ll have to merge some code or find some that has more testing within it..
I do think its what you said though where the DS needs shutting down and restarting if the action above is carried out.
sorry TWCC_BADCAP or TWCC_OPERATIONERROR i should have stated.
I think you set CAP_XFERCOUNT capability with -1 value.
- AuthorPosts