CLSCTX_INPROC_HANDLER,方式创建的时候,怎么获取MSWORD中的Applicaiton,Document接口。我试了几次好像都不行。
用CLSCTX_LOCAL_SERVER方式创建COM的时候,可以轻松的获取上面提到的接口,单无法做内嵌到其他窗口的功能。那位高手帮我解决一下这方面的问题,多谢
用CLSCTX_LOCAL_SERVER方式创建COM的时候,可以轻松的获取上面提到的接口,单无法做内嵌到其他窗口的功能。那位高手帮我解决一下这方面的问题,多谢
调试欢乐多
CComPtr<IOleObject> spObj;
if(FAILED(hr = spObj.CoCreateInstance(L"Word.Document", NULL, CLSCTX_INPROC)))
return hr;
创建了WORD的COM,如何获取MSWORD中的Applicaiton,Document接口
there were several helpful things generated for you that you aren't
using. Most notably is all the smart pointers derived from _com_ptr_t!
You also need to learn how to work with VARIANTs. The _variant_t class
makes it easy.
try
{
Word::_ApplicationPtr pWordApp ;
HRESULT hr = pWordApp.CreateInstance(
__uuidof( Word::Application ) ) ;
if ( hr == S_OK )
{
Word::DocumentsPtr pDocs = theApp.m_pWordApp->Documents ;
_variant_t vtFilename( _T("C:\\MyFile.doc") ) ;
Word::_DocumentPtr pDoc = pDocs->Open( &vtFilename ) ;
// etc.
}
}
catch ( _com_error & ce )
{
CString strMsg ;
strMsg.Format( _T("%s\n%S"), ce.ErrorMessage(),
(LPCWSTR)ce.Description() ) ;
AfxMessageBox( strMsg, MB_OK | MB_ICONSTOP ) ;
}
To my
knowledge, Microsoft assumes that anyone smart enough to choose C++ is
smart enough not to need documentation. :) They provide all
documentation for the Office Automation interface directed to VB users.
If you've got the October 2001 MSDN Library, and are using Word 2000,
like me, the path for the documentation is as follows:
Office Developer Documentation
- Office 2000 Documentation
- Microsoft Office 2000 Language Reference
- Microsoft Word 2000 Reference
- Microsoft Word Visual Basic Reference
For other versions of MSDN or Word, this may obviously vary.
It's actually not too hard to translate. Look at the VB help, then look
at the corresponding object interface in your TLH file. You should see
the analogies.