Ways to determine the native Office installation version share _c language

Source: Internet
Author: User

Copy Code code as follows:

#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",
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.