判断本机判断本机office安装版本的方法分享安装版本的方法分享
代码如下:
#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”,
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);
评论0