Click here to Skip to main content
15,898,680 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello..

Am newbie to this forum & MFC... Am getting Debug Assertion Failed

while using ActiveX control. Please guide me on this..My code looks

like this:

C++
//CMyProjectDlg.h
class CMyProjectDlg: public CDialog
{
public:
	CMyProject(CWnd* pParent = NULL);
	enum { IDD = IDD_CMYPROJECT_DIALOG };
	CMiDocView	m_MIDOCtrl;
//m_MIDOCtrl is the object for the class CMiDocView .Here CMiDocView is the class defined in other header file

protected:
BOOL  bReadOCRByMODIAXCtrl(CString csFilePath,  CString &csText);

};


C++
//CMyProjectDlg.cpp
BOOL CMyProjectDlg::bReadOCRByMODIAXCtrl(CString csFilePath, CString &csText)
{
BOOL bRet  = TRUE;
HRESULT hr = 0;
csText.Empty();
	

IUnknown   *pVal    = NULL;
IDocument  *IDobj   = NULL;
ILayout	   *ILayout = NULL;
IImages    *IImages = NULL;
IImage     *IImage  = NULL;
IWords     *IWords  = NULL;
IWord      *IWord   = NULL;

try{

pVal = (IUnknown *) m_MIDOCtrl.GetDocument();

//After Executing this statement, I used to Debug Assertion failed...

if ( pVal != NULL )
{
hr = pVal->QueryInterface(IID_IDocument,(void**) &IDobj);
if ( SUCCEEDED(hr) )
{
hr = IDobj->OCR(miLANG_SYSDEFAULT,1,1);
if ( SUCCEEDED(hr) )
{
IDobj->get_Images(&IImages);
long iImageCount=0;
IImages->get_Count(&iImageCount);
for ( int img =0; img<iImageCount;img++)
{
IImages->get_Item(img,(IDispatch**)&IImage);
IImage->get_Layout(&ILayout);
long numWord=0;
ILayout->get_NumWords(&numWord);
ILayout->get_Words(&IWords);
IWords->get_Count(&numWord);

for ( long i=0; i<numWord;i++)
{
IWords->get_Item(i,(IDispatch**)&IWord);
CString csTemp;
BSTR result;
IWord->get_Text(&result);
char buf[256];
sprintf(buf,"%S",result);
csTemp.Format("%s",buf);
csText += csTemp;
csText +=" ";

//Release all objects
IWord->Release();
IWords->Release();
ILayout->Release();
IImage->Release();
}
IImages->Release();
} else {
bRet = FALSE;
}
} else {
bRet = FALSE;
}
IDobj->Close(0);
IDobj->Release();
pVal->Release();
} else {
bRet = FALSE;
}
pVal    = NULL;
IDobj   = NULL;
ILayout = NULL;
IImages = NULL;
IImage  = NULL;
IWords  = NULL;
IWord   = NULL;
}
catch(...)
{
}

return bRet;
}


C++
void CMyProjectDlg::OnBnClickedOCR()
{

  CMyProjectDlg *ob = new CMyProjectDlg;

((CMiDocView *)GetDlgItem(IDC_MIDOCVIEW1))->SetFileName("E:\\aaa.tiff");

//IDC_MIDOCVIEW is the ID for the ActiveX control..

((CMiDocView *) GetDlgItem( IDC_MIDOCVIEW1 ))->SetFitMode(1);

  CString cs;
  ob->bReadOCRByMODIAXCtrl("E:\\aaa.tiff",cs);

  delete ob;

}



After clicking OCR button, I used to get Debug assertion failed on the line:
pVal = (IUnknown *) m_MIDOCtrl.GetDocument();
When i press retry, the control goes to
ASSERT(m_pCtrlsite != NULL ) in winocc.cpp
while Debugging i came to know that {CMIDOCView hWnd = 0x0000000}.

Please can anyone suggest me what am doing wrong here ??

Thank you all..
Posted

1 solution

I cant see any value assigned to m_MIDOCtrl; in your whole code life cycle.Obviously m_MIDOCtrl will end up with a null value when referenced.
 
Share this answer
 
Comments
Raj_Learner 1-Oct-12 6:59am    
Hi Perlibrain.. Instead of using ob->bReadOCRByMODIAXCtrl("E:\\aaa.tiff",cs); If we use only bReadOCRByMODIAXCtrl("E:\\aaa.tiff",cs); It works fine & m_MIDOCtrl will not be NULL.
But if i Dynamically create a object of class CMyProject & accessing function through object like this:
CMyProject *ob=new CMyProject;
ob->bReadOCRMODIAXCtrl("E:\\aaa.tiff",cs); will get the Error..

Is this wrong ??
perilbrain 1-Oct-12 7:08am    
this implies value is getting set somewhere. why dont you try ob->m_MIDOCtrl=this->m_MIDOCtrl and see if its working.
Raj_Learner 1-Oct-12 7:29am    
Nope still same error.. Basically i have to run my app continuously for long hours like this:
for(;;)
{
//Other functions..
bReadOCRMODIAXCtrl("E:\\aaa.tiff",cs);
//some other functions..
}

The problem with this code is: After running this for certain time, CPU Memory goes on increases & finally App goes out of scope..

So.. I thought of using Dynamically Allocation i.e.,
for(;;)
{
CMyProject * ob = new CMyProject; //Create the object.
ob->breadOCRMODIAxCtrl("E:\\aaa.tiff",cs);

delete ob; //Release the memory.
}
Please suggest me on this..
perilbrain 1-Oct-12 10:59am    
No doing that way wont help, because you will still end up leaving so much of memory leaks.In breadOCRMODIAxCtrl you are trying to release objects before catch statement so if any error occurs there will be memory leak.Put release routines below catch so that if any of them is allocated(NOT NULL) it will be deallocated.
Raj_Learner 3-Oct-12 1:01am    
Oh Thanks Perilibrain .. U pointed me in a right direction :)

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