如何在线程中读取DOC文件内容?

Stand_Alone_Complex Stand_Alone_Complex 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
创建了一个对话框的MFC工程
//全局变量
Documents docs;
Selection selection;
_Document doc;
_Application wordApp;
//***************************

CString *pstr,path,str;
int i;

path="C:\\Documents and Settings\\Administrator\\桌面\\新建文件夹\\1.doc";//文件目录
LPDISPATCH pd;
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND,VT_ERROR),vZ((short)0);
if(AfxOleInit()
&& wordApp.CreateDispatch("Word.Application",NULL))
{

wordApp.SetVisible(1);
docs.AttachDispatch(wordApp.GetDocuments());
AfxMessageBox("here");
pd=docs.Open(COleVariant(path),vFalse,vTrue,vFalse,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vOpt,vZ,vOpt,vOpt);

doc.AttachDispatch(pd);
//AfxMessageBox("here");
selection=wordApp.GetSelection();
selection.GetSections();
selection.WholeStory();
content=selection.GetText();
AfxMessageBox(content);
selection.ReleaseDispatch();

doc.Close(vOpt,vOpt,vOpt);
doc.ReleaseDispatch();
wordApp.Quit(vFalse,vOpt,vOpt);
wordApp.ReleaseDispatch();
}
//以上代码在主程序中运行正常,读出了word文档的内容
//但是放在由AfxBeginThread开启的线程中就总在docs.Open这一步失败
//显示:unhandled exception in WordReader.exe (KERNEL32.dll) 0xE06D7363 Micsoft C++ Exception
//这是为何???
...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部