Click here to Skip to main content
16,016,227 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my application need some scanner support ,I thought it is a good idea to get into TWAIN and try it out.after that I had an exit error that is driving me nuts as an Debug Assertion Failed....
in cmdtarg.cpp line 40 CCmdTarget::~CCmdTarget because m_dwRef is greater than 1 (in this case it is 2)


What I have tried:

CCmdTarget::~CCmdTarget()
{
	if (m_xDispatch.m_vtbl != 0)
		((COleDispatchImpl*)&m_xDispatch)->Disconnect();
	ASSERT(m_dwRef <= 1);
	m_pModuleState = NULL;
}



//Error message

'ScannerApp.exe' (Win32): Unloaded 'C:\Windows\twain_32.dll'
Debug Assertion Failed!

Program: C:\Windows\SYSTEM32\mfc140d.dll
File: d:\a01\_work\11\s\src\vctools\VC7Libs\Ship\ATLMFC\Src\MFC\cmdtarg.cpp
Line: 40
Posted
Updated 9-Dec-22 8:58am

I don't have an answer for you because there isn't enough code posted to have one. I recommend that you check out some sample code to see if you are overlooking anything or just doing something incorrectly. Here are a few samples I found, two of which are here :
A C++ Wrapper for TWAIN[^]
A Copy Utility using TWAIN[^]
TWAIN sample Data Source and Application[^]
Hopefully one of them can help you.
 
Share this answer
 
Take a look at m_dwRef assert in ~CCmdTarget[^]

It seems an object is not being released somewhere in your code, for whatever reason.
because m_dwRef is greater than 1 - Google Search[^]
 
Share this answer
 
Assertion on

ASSERT(m_dwRef <= 1);


Means just one thing: You forgot to call Release() prior object was destroyed
 
Share this answer
 
There is a hint that different versions of MFC combined in one project may have led to a similar problem.
m_dwRef assert in ~CCmdTarget[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900