| 发表于:2007-08-27 19:18:43 楼主 |
我获得我机器上word的版本为word.application.8 我在用createdispatch( "word.application.8 ") 但创建失败 在createdispatch函数中的afxgetclassidfromstring()函数 返回为0 偶谁能解释下吗? 谢谢叻. 初始化函数代码如下: void coutputword::init() { cstring strdevicename=m_strdevicename; lpdispatch pdisp; lpunknown punk; clsid clsid; const int nwordnum=10; const cstring wordprog[]= { "word.application.7 " , "word.application.8 " , "word.application.9 " , "word.application.10 " , "word.application.11 " , "word.application.12 " , "word.application.13 " , "word.application.14 " , "word.application.15 " , "word.application.16 " }; uses_conversion; cstring strwordprog; for(int nwordid=0; nwordid < nwordnum; ++nwordid) { ::clsidfromprogid(a2ole(wordprog[nwordid]), &clsid); //从注册表中获得信息 if(clsid != guid_null) { strwordprog=wordprog[nwordid]; break; } } if(clsid == guid_null) { return; } if(::getactiveobject(clsid, null, &punk) == s_ok)//如果word已经打开 { verify(punk-> queryinterface(iid_idispatch, (void**) &pdisp) == s_ok); m_app.attachdispatch(pdisp); punk-> release(); m_bwordopen=true; trace( " attach complete\n "); } else { if(!m_app.createdispatch(strwordprog))//创建word对象 这里创建失败 { trace( "create failed\n "); return; } m_bwordopen=false; trace( " create complete\n "); } m_app.setvisible(true);//显示word窗口 lpdispatch pdocuments; pdocuments=m_app.getdocuments(); documents documents; documents.attachdispatch(pdocuments); lpdispatch pdocument; variant filename; filename.vt=vt_bstr; filename.bstrval=strdevicename.allocsysstring(); variant confirmconversions, readonly; variant addtorecentfiles, passworddocument; variant passwordtemplate, revert; variant writepassworddocument, writepasswordtemplate; variant format, encoding, visible; confirmconversions.vt=vt_i2; readonly.vt=vt_i2; addtorecentfiles.vt=vt_i2; passworddocument.vt=vt_bstr; passwordtemplate.vt=vt_bstr; revert.vt=vt_i2; writepassworddocument.vt=vt_bstr; writepasswordtemplate.vt=vt_bstr; format.vt=vt_i2; encoding.vt=vt_i4; visible.vt=vt_i2; cstring strtemp= " "; confirmconversions.ival=0; readonly.ival=0; addtorecentfiles.ival=1; passworddocument.bstrval=strtemp.allocsysstring(); passwordtemplate.bstrval=strtemp.allocsysstring(); revert.ival=0; writepassworddocument.bstrval=strtemp.allocsysstring(); writepasswordtemplate.bstrval=strtemp.allocsysstring(); format.ival=0; encoding.lval=0; visible.ival=1; //在外层已经处理了,如果文件在存在,那一定是打开的 cfilefind filefinder; if(filefinder.findfile(strdevicename)) pdocument=documents.open(&filename, &confirmconversions, &readonly, &addtorecentfiles, &passworddocument, &passwordtemplate, &revert, &writepassworddocument, &writepasswordtemplate, &format); else pdocument=documents.add(); m_document.attachdispatch(pdocument); lpdispatch pselection; pselection=m_app.getselection(); m_selection.attachdispatch(pselection); variant v1,v2; v1.vt=vt_i2; v2.vt=vt_i2; v1.ival=6; v2.ival=0; m_selection.endkey(&v1, &v2); lpdispatch pfont; pfont=m_selection.getfont(); m_font.attachdispatch(pfont); } |
|
|
|
|