Skip to content

Unexpected results returning struct with floats in RCW #10901

Closed
@JeremyKuhne

Description

@JeremyKuhne

In trying to wrap ID2D1RenderTarget::GetSize which returns [D2D_SIZE_F] the expected way it would corrupt the stack.

Flipping it to an out parameter made it work, but I'm unclear as to why. Discussing with @davidwrighton, there might be a bug here. I was unable to create the same scenario via straight [DllImport]s against a sample project. I'll see if I can get a smaller repro together.

In d2d1.h it is defined as:

STDMETHOD_(D2D1_SIZE_F, GetSize)(
    ) CONST PURE;

Which expands to:

virtual __declspec(nothrow) D2D1_SIZE_F __stdcall GetSize() const = 0;

The struct is:

typedef struct D2D_SIZE_F
{
    FLOAT width;
    FLOAT height;
} D2D_SIZE_F;

I wrapped this here (SizeF is from System.Drawing):

[PreserveSig]
void GetSize(out SizeF size);

// Doesn't Work:
// [PreserveSig]
// SizeF GetSize();

In the WInterop project I have a test Direct2dTests.RenderTarget.GetSize() that exercises it. One can also look at this by tweaking the Direct2dDemo project (i.e. call the method) which runs on .NET Core and sets up a render target that you can use.

As stated, I'll try and get a smaller COM repro together for this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions