CoInitialize(NULL);//初始化COM,与最后一行CoUninitialize对应 //CPageSetup pagesetup=doc.get_PageSetup();//页面设置相关,没用到 //CApplication app; if (!m_app.CreateDispatch(_T("word.application"))) //启动WORD { MessageBox(NULL, L"waring", L"CreateDispatch word.application", MB_OK); return LAUCHWORDERROR; } //AfxMessageBox(_T("WORD 已经运行启动啦,你可以用Ctrl+Alt+Del查看")); //m_app.put_Visible(TRUE); //设置WORD可见。 m_app.put_Visible(TRUE); //设置WORD不可见。 LPDISPATCH tmpDocs = NULL; tmpDocs = m_app.get_Documents(); if (tmpDocs == NULL) { MessageBox(NULL, L"waring", L"tmpSel empty", MB_OK); return GETDOCUMENTSERROR; } COleVariant varOPt(DISP_E_PARAMNOTFOUND, VT_ERROR); m_docs = tmpDocs; //m_docs.Add(new CComVariant(_T("")), new CComVariant(FALSE), new CComVariant(0), new CComVariant());//创建新文档 m_docs.Open(COleVariant(savePath), varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt, varOPt); //LPDISPATCH tmpDoc = NULL; tmpDoc = m_app.get_ActiveDocument();//活动文档 if (tmpDoc == NULL) { MessageBox(NULL, L"waring", L"tmpDoc empty", MB_OK); return GETACTIVEDOCUMENTERROR; } m_doc = tmpDoc; m_docs.ReleaseDispatch(); m_doc.ReleaseDispatch(); m_app.Quit(new CComVariant(FALSE), new CComVariant(), new CComVariant()); m_app.ReleaseDispatch(); CoUninitialize();//对应CoInitialize
标签:文件,CComVariant,NULL,word,app,varOPt,new,打开,tmpDoc From: https://www.cnblogs.com/hshy/p/17651494.html