clrinterop / clrinterop-issues-sandbox

0 stars 0 forks source link

'Data4' section of GUID incorrectly generated as a string #75

Open jozefizso opened 16 years ago

jozefizso commented 16 years ago

Issue from Mon, 13 Oct 2008 17:55:38 GMT
Originally opened at https://clrinterop.codeplex.com/workitem/2453


When converting a GUID, the interop assistant thinks that Data4 should be a string:   [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet=System.Runtime.InteropServices.CharSet.Ansi)] public struct GUID { /// unsigned int public uint Data1;

/// unsigned short
public ushort Data2;

/// unsigned short
public ushort Data3;

/// unsigned char[8]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=8)]
public string Data4;

}   It’s really an array of bytes, and even calling System.Text.Encoding.Unicode.GetString(bytes) or System.Text.Encoding.ASCII.GetString(bytes) didn’t create the correct string. Changing the marshalling definition to an array of bytes worked:   [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] internal byte[] Data4;     This came from generating the definition for WINTRUST_BLOB_INFO from the SDK (by pasting it in.)

jozefizso commented 16 years ago

Comment from Wed, 05 Nov 2008 01:07:58 GMT


Should be this whole structure converted to System.Guid?

jozefizso commented 16 years ago

Comment from Wed, 05 Nov 2008 16:15:10 GMT


Yes it should. The tool attempts to map a set of native types into the corresponding managed type. It looks like GUID slipped through in this case.

jozefizso commented 16 years ago

Comment from Thu, 06 Nov 2008 16:21:58 GMT


Yes. The intention of this part of the tool is to not display a native type when there is a better equivalent managed type.