使用ActiveX控件时调试断言失败 [英] Debug Assertion Failed while using ActiveX control

查看:93
本文介绍了使用ActiveX控件时调试断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好..

我是这个论坛的新手& MFC ...调试断言失败

在使用ActiveX控件时.请指导我..我的代码看起来

像这样:

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:

//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);

};





//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;
}





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;

}




单击OCR按钮后,我习惯于在以下行获得Debug断言失败:
pVal =(IUnknown *)m_MIDOCtrl.GetDocument();
当我按重试时,控件转到
在winocc.cpp中ASSERT(m_pCtrlsite!= NULL)
在调试时,我知道{CMIDOCView hWnd = 0x0000000}.

请任何人能建议我在这里做错了吗?

谢谢大家..




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..

推荐答案

我看不到整个代码生命周期中分配给m_MIDOCtrl;的任何值.显然m_MIDOCtrl 将以空值结尾引用时.
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.


这篇关于使用ActiveX控件时调试断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆