dlr icon indicating copy to clipboard operation
dlr copied to clipboard

Variant Interop Bug

Open weltkante opened this issue 4 years ago • 3 comments

While reviewing the WinForms implementation of VARIANT interop I was comparing with various implementations found on the web and I noticed you are treating VT_INT/VT_UINT as IntPtr/UIntPtr.

The resolution in the WinForms PR was that VT_INT/VT_UINT need to be 4 byte, even though the C/C++ headers are a bit ambigous the spec is clear and its also what native code is doing.

Just leaving you this as a note in case you want to fix your implementation.

https://github.com/dotnet/winforms/pull/3197#discussion_r423937631

In the headers (wtypes.h) it is written up as such:

/*
...
 *  VT_INT              [V][T][P][S]  signed machine int
 *  VT_UINT             [V][T]   [S]  unsigned machine int
*/

But... things like VariantCopyInd() always treat them as a 4 byte value. This aligns with the MS-OAUT specification which states:

VT_INT: Context Description V, S, T Either the specified type, or the type of the element or contained field MUST be a 4-byte signed integer.

VT_UINT: Context Description V, S, T Either the specified type, or the type of the element or contained field MUST be a 4-byte unsigned integer.

weltkante avatar May 13 '20 12:05 weltkante

Also looking at documentation for PROPVARIANT (https://docs.microsoft.com/en-us/windows/win32/api/propidlbase/ns-propidlbase-propvariant)

VT_INT 22 intVal 4-byte signed integer value (equivalent to VT_I4).
VT_UINT 23 uintVal 4-byte unsigned integer (equivalent to VT_UI4).

hughbe avatar May 13 '20 12:05 hughbe

Thanks for the report. It seems like .NET runtime has similar SetAsByref methods, would these also be incorrect?

slozier avatar May 13 '20 16:05 slozier

Yes, I'll drop them a note as well. Thanks for the hint.

weltkante avatar May 13 '20 16:05 weltkante