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.