clrinterop / clrinterop-issues-sandbox

0 stars 0 forks source link

Incorrect marshalling of VARIANT_BOOL #14

Open jozefizso opened 15 years ago

jozefizso commented 15 years ago

Issue from Wed, 07 Jan 2009 06:01:45 GMT Originally opened at https://clrinterop.codeplex.com/workitem/3009


TLBIMP converts VARIANT_BOOL to System.Boolean if you use /v2 option.   --- COM --- struct A { VARIANT_BOOL B0; VARIANT_BOOL B1; VARIANT_BOOL B2; VARIANT_BOOL B3; };   --- C# --- struct A { bool B0; bool B1; bool B2; bool B3; };   By default System.Boolean is marshaled as BOOL (4 bytes, TRUE = 1, FALSE = 0) but VARIANT_BOOL is different (2 bytes, VARIANT_TRUE = 0xFFFF, VARIANT_FALSE = 0). So, additional MarshalAs attribute is required.   Should be   --- C# --- struct A { [MarshalAs(UnmanagedType.VariantBool)] bool B0; [MarshalAs(UnmanagedType.VariantBool)] bool B1; [MarshalAs(UnmanagedType.VariantBool)] bool B2; [MarshalAs(UnmanagedType.VariantBool)] bool B3; };   The bug is critical because field offsets and structure sizes can be different.   See attached proposed patch.

jozefizso commented 15 years ago

Comment from Tue, 20 Jan 2009 08:33:45 GMT


Assign to EricFu to see if we can get a quick fix on this.

jozefizso commented 15 years ago

Comment from Thu, 05 Feb 2009 09:35:06 GMT


A code change is checked in. "MarshalAs(UnmanagedType.VariantBool)" attribute is added to the bool field, when "/v2" switch converts VARIANT_BOOL to managed bool. For bool parameter, the attribute is not added, according to the old TlbImp behavior. This bug only happens on P/Invoke case. For COM interop case, the attribute is not needed.