我包含了头文件comutil.h
try{
Word::_ApplicationPtr pApp=NULL;
pApp.CreateInstance (__uuidof(Word::Application),NULL);
pApp->PutVisible (VARIANT_TRUE);
_variant_t str1;
str1.SetString(strPath);
Word::_DocumentPtr pDoc=pApp->GetDocuments()->Open(&str1);
_bstr_t content=pDoc->Content->Text;//
Data=(LPCTSTR)content; TRACE("Word content: %s \n", (LPCTSTR)(_bstr_t)content);
pDoc->Close();
pApp->Quit();
}
catch(...)
{
AfxMessageBox(_T("读文件出现异常!"));
}
编译能通过,但执行到_variant_t str1;时就出现了异常.我新建了一个工程,也在里面定义了一个_variant_t变量,包含了对应的头文件,编译有连接错误,请问是不是没加载对应的库comsuppw.lib 或comsuppwd.lib 或者是别的问题?
try{
Word::_ApplicationPtr pApp=NULL;
pApp.CreateInstance (__uuidof(Word::Application),NULL);
pApp->PutVisible (VARIANT_TRUE);
_variant_t str1;
str1.SetString(strPath);
Word::_DocumentPtr pDoc=pApp->GetDocuments()->Open(&str1);
_bstr_t content=pDoc->Content->Text;//
Data=(LPCTSTR)content; TRACE("Word content: %s \n", (LPCTSTR)(_bstr_t)content);
pDoc->Close();
pApp->Quit();
}
catch(...)
{
AfxMessageBox(_T("读文件出现异常!"));
}
编译能通过,但执行到_variant_t str1;时就出现了异常.我新建了一个工程,也在里面定义了一个_variant_t变量,包含了对应的头文件,编译有连接错误,请问是不是没加载对应的库comsuppw.lib 或comsuppwd.lib 或者是别的问题?
Header: comutil.hLib: comsuppw.lib or comsuppwd.lib (see /Zc:wchar_t (wchar_t Is Native Type) for more information)在项目属性的连接页里面加入comsuppw.lib or comsuppwd.lib
#pragma comment(lib, "comsuppw.lib")
#pragma comment(lib, "comsuppwd.lib")
加到stdafx.h
return;
这个也不要忘了
return;
加在哪里啊?
return; try{
Word::_ApplicationPtr pApp=NULL;
.....
return
这句是什么功能啊?
怎么办?
str1.SetString(strPath);
是否文件确实存在
如果不存在的话
pDoc智能指针可能会有问题
strPath="C:\Documents and Settings\Rui.2B9F317BD5854FF\桌面\新建文件夹 (5)\粗分类结果.doc"
strPath是通过dlg.GetPathName()得到的;
dlg是CFileDialog;
是不是"C:"后面应该用"\\"啊?
但是又执行
catch(...)
{
AfxMessageBox(_T("读文件出现异常!"));
}
了而且Word打开了,但没打开任何文件,就一个word空框架
C:\\Documents and Settings\\Rui.2B9F317BD5854FF\\桌面\\新建文件夹 (5)\\粗分类结果.doc"
还是弹出
"dubug assertion failed!"