Home › Forums › TWAIN Classic › "Application error" or "TWRC_FAILURE" er
- This topic has 4 replies, 3 voices, and was last updated 16 years, 7 months ago by sparge.
- AuthorPosts
Hi,all.
We have some problem. “Application error” or “TWRC_FAILURE” error occur in (d) phase,
when the loop program as below run more than 32750times.
What should we do to avoid this problem?(a) LoadLibrary DSM(TWAIN_32.DLL)
(b) DG_CONTROL/DAT_PARENT/MSG_OPENDSM(open DSM)
(c) DG_CONTROL/DAT_IDENTITY/MSG_GETDEFAULT(select DS)
(d) DG_CONTROL/DAT_IDENTITY/MSG_OPENDS(open DS)
(e) DG_CONTROL/DAT_IDENTITY/MSG_CLOSEDS(close DS)
(f) DG_CONTROL/DAT_PARENT/MSG_CLOSEDSM(close DSM)
(g) FreeLibrary DSM(TWAIN_32.DLL)OS:Windows XP Professional SP2 / Windows XP Emmbeded SP2
Version: TWAIN.DLL 1.7.0.0
TWAIN_32.DLL 1.7.1.1
Development:Visual Studio 2005 Professional SP1Best regards.
which error?
are you accessing twain_32.dll directly in c++?
are you using a wrapper?
what source are you opening? – the name version and whatnotis freeLibrary successful in each loop?
hows the system memory holding up? – any leaks?you’re 16 loops from being suspect (32k), are you doing anything silly – out of bounds or anything?
What should we do to avoid this problem?
…only run the loop 32749 times?
.Thank you for your advice.
> which error?
> are you accessing twain_32.dll directly in c++?
> are you using a wrapper?
We access twain_32.dll directly in c++. We don’t use MFC.
See the source code below.> what source are you opening? – the name version and whatnot
CanoScan 9900F 8.2
FUJITSU fi-60F 9.17> is freeLibrary successful in each loop?
Yes , it is.> hows the system memory holding up? – any leaks?
We think memory usage is OK with Windows task manager monitoring.
And we don’t find memory leak in the program as below.
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_WNDW);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW);
_CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_WNDW);
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);> you’re 16 loops from being suspect (32k), are you doing anything silly – out of bounds or anything?
We don’t access an out of bounds momory.> …only run the loop 32749 times?
That’s correct. But, we are afraid of these errors occur less than 32750times. So we want to know the reason.Thank you.
source codefor (ccount = 1; counter >= ccount; ++ ccount)
{
if (!p->twain->Initialize(::AfxGetApp()->m_pMainWnd->m_hWnd))
{
p->fStop = TRUE;
str.Format(_T(“OpenDSM error: #%d”), ccount);
Logging(LPCTSTR(str));
break;
}// Open scanner
if (!p->twain->GetCurrentDataSource(p->ds) == TWRC_SUCCESS)
{
p->fStop = TRUE;
str.Format(_T(“GetCurrentDS error: #%d”), ccount);
Logging(LPCTSTR(str));
break;
}if (p->twain->OpenDS(p->ds) != TWRC_SUCCESS)
{
p->fStop = TRUE;
str.Format(_T(“OpenDS error: #%d”), ccount);
Logging(LPCTSTR(str));
break;
}// Cloese scanner
if (p->twain->CloseDS(p->ds) != TWRC_SUCCESS)
{
p->fStop = TRUE;
str.Format(_T(“CloseDS error: #%d”), ccount);
Logging(LPCTSTR(str));
break;
}if (!p->twain->Finalize())
{
p->fStop = TRUE;
str.Format(_T(“CloseDSM error: #%d”), ccount);
Logging(LPCTSTR(str));
break;
}
}BOOL CTwain::Initialize(HWND hWnd)
{
BOOL bResult = FALSE;
Finalize();m_hWnd = hWnd;
// Load Twain_32.DLL
m_hModule = ::LoadLibrary(_T(“Twain_32.DLL”));
if (m_hModule)
{
// Entry
m_fpDSM_Entry = (DSMENTRYPROC)GetProcAddress(m_hModule, MAKEINTRESOURCE(1));
if (m_fpDSM_Entry == NULL)
{
Finalize();
}
else
{
// Open DSM
if (m_fpDSM_Entry(&m_appID, NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF)&hWnd) == TWRC_FAILURE)
{
Finalize();
}
else
{
bResult = TRUE;
}
}
}
return bResult;
}BOOL CTwain::Finalize()
{
if (m_hModule)
{
m_fpDSM_Entry(&m_appID, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, &m_hWnd);
::FreeLibrary(m_hModule);
}
m_hModule = NULL;
m_fpDSM_Entry = NULL;return TRUE;
}while I think about that,
if you examine the twIdentity returned in
DG_CONTROL/no/MSG_GETDEFAULT(select DS)
does the struc look *right* are you getting a valid twIdentity back from the DSM?
you said “Application error” or “TWRC_FAILURE”
which? it is an “Application error” or is it “TWRC_FAILURE”? – seems that there is a significant difference
If it is twrc_Failure check the twcc_ it may help determine the source. otherwise… i dunno otherwise… GetLastError provide any help? (no, I’m not sure if it does)what happens on loop 32751 (and on loop 32770) ?
If you don’t break out of the loop when rc != success and continue for another couple of loops, do you start geting success again?Does starting the app again ‘fix’ it or do you have to reboot to get rc == success?
(I’m just throwing darts with my eyes closed here)
.
.
Hi Kenji,
What a great question! I have encountered problems like this with lots of scanners when repeatedly opening and closing the DS, and have long suspected that there must be a very longstanding memory-management bug either in the DSM or in Windows. When I first raised this a few years ago, the general perception seemed to be that no-one sane ever opened and closed their DS more than a handful of times in a session, so my observation was purely of academic interest – and the TWAIN guys assured me that the DSM was ancient, venerable and watertight code anyway …
Furthermore, I write my apps in FORTRAN, so there is always the suspicion that some cross-compiler issue is to blame. You are the first person I have come across to have found and reported the problem, coding directly in the same language as specified in the TWAIN standard.
It’s particularly interesting that you get the issue with a Fujitsu scanner. I only wish the budgets I get given to play with came anywhere near being able to afford one. The scanners I work with are cheap and cheerful, so my experience can always be discounted on grounds of shoddily-written scanner drivers if not on grounds of mixed-language programming.
Good luck with solving the mystery. You will need it.
Andy
- AuthorPosts