Home › Forums › TWAIN Classic › "Application error" or "TWRC_FAILURE" er › Reply To: "Application error" or "TWRC_FAILURE" er
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 code
for (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;
}