Click here to Skip to main content
15,897,187 members

Debug Assertion Failed while using ActiveX control

Raj_Learner asked:

Open original thread
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..
Tags: MFC

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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