-
January 20th, 2014, 02:37 AM
#1
Automation MS Word in Active-X container. Please help to properly create the object.
Good day.
I`m working with MS Visual Studio 6. Trying to connect Word server with my window.
This is call server in my class CXContainerView, inherit from CScrollView:
Code:
void CXContainerView::CreateWord()
{
::CoInitialize(NULL);
_Document doc;
_Application m_app;
LPDISPATCH lpDisp;
CLSID clsid;
COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
CXContainerDoc* pDoc = GetDocument();
CXContainerCntrItem* pItem = new CXContainerCntrItem(pDoc);
HRESULT hr = CLSIDFromProgID(L"Word.Application", &clsid);
if(FAILED(hr))
{
::MessageBox(NULL, "CLSIDFromProgID() failed", "Error",0x10010);
GetDocument()->m_pChild->PostMessage(WM_CLOSE);
*(GetDocument()->m_succeed) = false;
return;
}
if(!pItem->CreateFromFile(pDoc->m_RtfTemplate.GetBuffer()))
{
AfxMessageBox("Ошибка при открытии файла MS Word", MB_ICONSTOP);
GetDocument()->m_pChild->PostMessage(WM_CLOSE);
*(GetDocument()->m_succeed) = false;
return;
}
else
pItem->DoVerb(OLEIVERB_SHOW, this);
ASSERT_VALID(pItem);
m_pSelection = pItem;
pDoc->UpdateAllViews(NULL);
pDoc->m_pChild->ShowWindow(SW_HIDE);
doc.CreateDispatch("Word.Document");
doc.AttachDispatch(pItem->GetIDispatch(),TRUE);
m_app = doc.GetApplication(); // <- i want to get pointer to the Word application and its falls
}
It works in debug version but falls in release. Feels my fifth point, what I call it in the wrong way. Prompt how to do it right please.
-
January 20th, 2014, 05:05 AM
#2
Re: Automation MS Word in Active-X container. Please help to properly create the obje
Victor Nijegorodov
-
January 20th, 2014, 05:26 AM
#3
Re: Automation MS Word in Active-X container. Please help to properly create the obje
Thanks. But i`d like to know: did i write correct code?
-
January 20th, 2014, 05:35 AM
#4
Re: Automation MS Word in Active-X container. Please help to properly create the obje
Originally Posted by cupuyc
...
It works in debug version but falls in release.
Originally Posted by cupuyc
Thanks. But i`d like to know: did i write correct code?
How can this code be correct if it fails in Release build?
Besides this code produces the memory leaks: you create CXContainerCntrItem* pItem with new, but do not delete it!
Victor Nijegorodov
-
January 20th, 2014, 05:44 AM
#5
Re: Automation MS Word in Active-X container. Please help to properly create the obje
I mean: did i write all correct with com technology? may be i invoke word-server incorrectly.
and i delete pItem later.
-
January 20th, 2014, 06:00 AM
#6
Re: Automation MS Word in Active-X container. Please help to properly create the obje
Originally Posted by cupuyc
I mean: did i write all correct with com technology? may be i invoke word-server incorrectly.
I don't know.
However, some words about your code:
Originally Posted by cupuyc
Code:
void CXContainerView::CreateWord()
{
::CoInitialize(NULL);
_Document doc;
_Application m_app;
LPDISPATCH lpDisp;
CLSID clsid;
COleVariant covTrue((short)TRUE), covFalse((short)FALSE), covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
...
m_app = doc.GetApplication(); // <- i want to get pointer to the Word application and its falls
}
You didn't explain how it fails.
Besides, your m_app instance is defined locally inside CreateWord() method, and it cannot be used after this method returns. So this "get pointer to the Word application" does not make any sense!
Victor Nijegorodov
-
January 22nd, 2014, 07:58 AM
#7
Re: Automation MS Word in Active-X container. Please help to properly create the obje
I solved the problem. This source helped me: http://support.microsoft.com/kb/238611/en-us
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|