服务器之家

服务器之家 > 正文

判断本机office安装版本的方法分享

时间:2021-01-14 16:29     来源/作者:C语言教程网

复制代码 代码如下:


#include "msword.h"
HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp,
     LPOLESTR ptName, int cArgs...)
{
 // Begin variable-argument list
 va_list marker;
 va_start(marker, cArgs);

 

 if (!pDisp)
 {
  _putws(L"NULL IDispatch passed to AutoWrap()");
  _exit(0);
  return E_INVALIDARG;
 }

 // Variables used
 DISPPARAMS dp = { NULL, NULL, 0, 0 };
 DISPID dispidNamed = DISPID_PROPERTYPUT;
 DISPID dispID;
 HRESULT hr;

 // Get DISPID for name passed
 hr = pDisp->GetIDsOfNames(IID_NULL, &ptName, 1, LOCALE_USER_DEFAULT, &dispID);
 if (FAILED(hr))
 {
  wprintf(L"IDispatch::GetIDsOfNames(\"%s\") failed w/err 0x%08lx\n",
   ptName, hr);
  _exit(0);
  return hr;
 }

 // Allocate memory for arguments
 VARIANT *pArgs = new VARIANT[cArgs + 1];
 // Extract arguments...
 for(int i=0; i < cArgs; i++)
 {
  pArgs[i] = va_arg(marker, VARIANT);
 }

 // Build DISPPARAMS
 dp.cArgs = cArgs;
 dp.rgvarg = pArgs;

 // Handle special-case for property-puts
 if (autoType & DISPATCH_PROPERTYPUT)
 {
  dp.cNamedArgs = 1;
  dp.rgdispidNamedArgs = &dispidNamed;
 }

 // Make the call
 hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
  autoType, &dp, pvResult, NULL, NULL);
 if (FAILED(hr))
 {
  wprintf(L"IDispatch::Invoke(\"%s\"=%08lx) failed w/err 0x%08lx\n",
   ptName, dispID, hr);
  _exit(0);
  return hr;
 }

 // End variable-argument section
 va_end(marker);

 delete[] pArgs;

 return hr;
}

void Cwps_msword2013Dlg::OnBnClickedButton1()
{
 CString strAppName = OLESTR("word.application");
 bool bResult = false;
 IDispatch * wordApp;
 CLSID appClsid;
 if(S_OK == CLSIDFromProgID(strAppName, &appClsid))
 {
  if(S_OK == CoCreateInstance(appClsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&wordApp))
  {
   Word::_Application appWord;
   if(S_OK == wordApp->QueryInterface(IID_IDispatch, (void**)&appWord))
   {
    CString strVersion = _T("");
    strVersion = appWord.GetVersion();
    if(_ttoi(strVersion) >= 15.0)
    {
     bResult = true;
    }
   }

  }
  AutoWrap(DISPATCH_METHOD, NULL, wordApp, L"Quit", 0);
  wordApp->Release();
 }
 if(bResult)
  MessageBox(_T("ok"), _T("tip"));
 else
  MessageBox(_T("no"), _T("tip"));
 //return bResult;
}

 

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部