How do I call functions that receive floating point values using IDispatch.Invoke?

前端 未结 1 1524
一生所求
一生所求 2021-01-21 07:56

I\'m having trouble calling a function that has a floating point argument and a floating point result, using IDispatch.Invoke.

Here\'s a minimal reproductio

相关标签:
1条回答
  • 2021-01-21 08:55

    Well, that was a head-scratcher. The documentation for this "method" is very misleading, it is not a method. It behaves more like an indexed property and requires the DISPATCH_METHOD | DISPATCH_PROPERTYGET flags. CComPtr doesn't support that, you'll need to spin this by hand. This code worked:

        CComVariant result;
        CComVariant centimeters((float)2.0);
        DISPID dispid;
        LPOLESTR name = L"CentimetersToPoints";
        HRESULT hr = wordapp->GetIDsOfNames(IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispid);
        assert(SUCCEEDED(hr));
    
        DISPPARAMS dispparams = { &centimeters, NULL, 1, 0};
        hr = wordapp->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT,
                DISPATCH_METHOD | DISPATCH_PROPERTYGET, &dispparams, &result, nullptr, nullptr);
        assert(SUCCEEDED(hr));
    
    0 讨论(0)
提交回复
热议问题