VC++如何调用TextRange2Ptr接口的函数?

小鸟向前飞 2016-08-03 03:58:46
PowerPoint中怎么使用TextRange2Ptr接口?
我的代码如下:


TCHAR szFile[] = _T("C:\\Users\\Zhao Leo\\Desktop\\1.pptx");

_ApplicationPtr spApp;

spApp.CreateInstance(L"Powerpoint.Application");

PresentationsPtr spPresentations = spApp->GetPresentations();

_PresentationPtr spPresentation = spPresentations->Open(szFile, msoFalse, msoFalse, msoFalse);

SlidesPtr spSlides = spPresentation->GetSlides();

long nCnt = spSlides->GetCount();
_SlidePtr spSlide = spSlides->Item(static_cast<long>(1));

PowerPoint::ShapePtr spShape = spSlide->GetShapes()->Item(static_cast<long>(1));
PowerPoint::TextFramePtr spTextFrame = spShape->GetTextFrame();

string str = spTextFrame->GetTextRange()->Text;

PowerPoint::TextFrame2Ptr spTextFrame2 = spShape->GetTextFrame2();
MsoTriState bRet = spTextFrame2->HasText;

TextRange2Ptr spTextRange2 = spTextFrame2->GetTextRange();
string str2 = spTextRange2->Text;

spPresentation->Close();



上面做了两个测试,用TextFrame得到的接口都没有问题,可以取出text内容,但使用TextFrame2得到的接口,在spTextRange2->Text这一句这里抛出了异常:


0x00007FFD53E16892 (oleaut32.dll) (2016080303.exe 中)处有未经处理的异常: 0xC0000005: 执行位置 0x00007FFD53E16892 时发生访问冲突。


可以看到mso.tli中


#pragma implementation_key(1676)
inline _bstr_t TextRange2::GetText ( ) {
BSTR _result = 0;
HRESULT _hr = get_Text(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _bstr_t(_result, false);
}




_result的地址是0x00000000
这是什么原因?该怎么处理??

相同的操作,早vba中是可以的。
...全文
978 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

5,138

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧