Skip to content

Fix marshaling of NativeArrayInfo parameters#357

Merged
AArnott merged 1 commit into
microsoft:mainfrom
pziezio:fix-array-marshaling
Aug 18, 2021
Merged

Fix marshaling of NativeArrayInfo parameters#357
AArnott merged 1 commit into
microsoft:mainfrom
pziezio:fix-array-marshaling

Conversation

@pziezio

@pziezio pziezio commented Aug 12, 2021

Copy link
Copy Markdown
Contributor

Fixes #269 and many other problems with DirectX2D/11/12 etc.

When parameters with NativeArrayInfo are marshaled MarshalAsAttribute is sometimes missing.

https://github.com/microsoft/CsWin32/blob/main/src/Microsoft.Windows.CsWin32/PointerTypeHandleInfo.cs#L32
In this case marshalAs variable corresponds to element type of the array.
When there is no need for setting specific ArraySubType the MarshalAsAttribute is dropped altogether.
It should be set to just MarshalAs(UnmanagedType.LPArray) without specifying ArraySubType.

https://github.com/microsoft/CsWin32/blob/main/src/Microsoft.Windows.CsWin32/PointerTypeHandleInfo.cs#L57
There is exactly the same code in case of marshaling structs as array. Maybe that caused some confusion.
But in that case dropping MarshalAs is correct.

@ghost

ghost commented Aug 12, 2021

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@AArnott AArnott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@AArnott AArnott merged commit 9e72d1b into microsoft:main Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling ID2D1Factory.CreateGeometryGroup causes Access violation

2 participants