Misha Koshelev wrote:
+/* Macros for variant conversions */ +#define V_DECLARE \
- VARIANTARG vararg[pDispParams->cArgs]; \
- int iVarCount; \
- HRESULT hr = S_OK; \
- memset(vararg, 0, sizeof(vararg));
+#define V_PREPARE(n, type) \
- VariantInit(&vararg[n]); \
- hr = VariantChangeTypeEx(&vararg[n], &pDispParams->rgvarg[n], lcid, 0, VT_##type); \
- if (FAILED(hr)) \
- { \
*puArgErr = n; \
goto v_finish; \
- }
+#define V_PREPAREOPT(n, type) \
- VariantInit(&vararg[n]); \
- if (FAILED(VariantChangeTypeEx(&vararg[n], &pDispParams->rgvarg[n], lcid, 0, VT_##type))) \
VariantClear(&vararg[n]);
+#define V_PREPARED(n) (V_VT(&vararg[n]) != VT_EMPTY) +#define V(n, type) V_##type(&vararg[n]) +#define V_RETURN(value, type) \
- V_VT(pVarResult) = VT_##type; \
- V_##type(pVarResult) = value;
+#define V_FAIL hr = E_FAIL; +#define V_DEFAULT \
- default: \
hr = DISP_E_MEMBERNOTFOUND;
+#define V_FINISH \
- goto v_finish; /* suppress warnings about unused label v_free */ \
+v_finish: \
- for (iVarCount = 0; iVarCount < pDispParams->cArgs; iVarCount++) \
if (V_PREPARED(iVarCount)) \
VariantClear(&vararg[iVarCount]); \
- return hr;
This is quite ugly. You can at replace at least some of this with calls to DispGetParam.
A lot of the methods only have one parameter so will end up simpler without using these macros.