Not too long ago, I explained why why there is a weird wReserved value at the start of the DECIMAL structure. Markus Grohs pointed out in a comment that the way that decVal is overlaid on top of a VARIANT means that you have to be careful about the order in which you set the fields.

Given

DECIMAL value = ⟦ some value ⟧; VARIANT var; VariantClear(&var);

then you have to remember to set the vt last because it is overwritten by the wReserved inside the DECIMAL.

// Wrong var.vt = VT_DECIMAL; var.decVal = value; // oops, the wReserved overwrites the var.vt.

// Better var.decVal = value; // the wReserved overwrites var.vt var.vt = VT_DECIMAL; // but we fix it up immediately

The extra wReserved in the DECIMAL is like a bulky backpack that you wear as you go about your daily business. You usually forget that you have it on, until you turn around in a tight spot and accidentally knock something over.

The post A consequence of the weird <CODE>wReserved</CODE> value at the start of the <CODE>DECIMAL</CODE> structure appeared first on The Old New Thing.


From The Old New Thing via this RSS feed