Home > Software engineering >  MFC call word interface block occasionally
MFC call word interface block occasionally

Time:11-07

Clsids clsids;
Word: : _ApplicationPtr pWordApp;
Word: : DocumentsPtr pDocs;

CLSIDFromProgID (L Word "Application", & amp; Clsids);
PWordApp. CreateInstance (clsids);
PDocs=pWordApp - & gt; GetDocuments ();

CComVariant FileName (_T (" D: \ \ 123. Doc "));//open the word document
IDispatch * pDispatchDoc=pDocs - & gt; Open (& amp; FileName));
CComPtr & lt; Word: : _Document & gt; M_comptrActiveDoc=CComQIPtr<_Document & gt; (pDispatchDoc);//get the document

Int GetParagaphCount ()
{
CComQIPtr PParagraphs=m_comptrActiveDoc - & gt; GetParagraphs ();
Int nCount=1;
If (pParagraphs!=NULL)
{
nCount=pParagraphs - & gt; GetCount ();//this sentence sometimes block
}
}

Cstrings GetWholeString ()
{
If (m_comptrActiveDoc - & gt; The GetActiveWindow ()!=NULL)
{
CComQIPtr PPanes=m_comptrActiveDoc - & gt; The GetActiveWindow () - & gt; GetPanes ();
If (pPanes!=NULL)
{
CComQIPtr PSel (pPanes - & gt; The Item (1) - & gt; GetSelection ());
If (pSel!=NULL)
{
CComQIPtr PRange (pSel - & gt; GetRange ());
If (pRange!=NULL)
{
Retrieves the hr=pRange - & gt; WholeStory ();
If (SUCCEEDED (hr))
{
StrRet=(char *) (pRange - & gt; The GetText ());
}
}
}
}
}
}
Above is I now in the operation of the word's part of the code, in the actual process, is to open a word document, and then there are other mechanism called word's interface to obtain the total number of paragraphs or obtain all text,
Actual operation process, found that the program runs three or four hours later, interface sometimes blocks to inside ( ) of the red, cause all the main interface card to death,
Everyone a great god help to look at, what could be causing the, how to solve ah,

CodePudding user response:

Debug mode, jammed, pause, take a look at all the threads, whether the information such as abnormal (Except)
Under the task manager focus on memory at the same time, the handle, the change of the number of GDI, see if there is a memory, resource leaks

  • Related