在 2019/11/24 2:34, Nikolay Sivov 写道:
> 
> Thanks, I think mingw headers are broken when in C mode. Like I said, vtbl
> method prototype should be:
> 
>      D2D1_SIZE_F * (STDMETHODCALLTYPE *GetSize)(
>          ID2D1HwndRenderTarget *This,
>          D2D1_SIZE_F *__ret);
> 
> In Wine we generate it from .idl sources, fixed up inline wrapper is like
> this:
> 
> static FORCEINLINE D2D1_SIZE_F
> ID2D1HwndRenderTarget_GetSize(ID2D1HwndRenderTarget* This) {
>      D2D1_SIZE_F __ret;
>      return *This->lpVtbl->GetSize(This,&__ret);
> }
> 
> 
> 

As Microsoft doesn't provide C interfaces we have to look at their C++
declarations:

```
    STDMETHOD_(D2D1_SIZE_F, GetSize)(
        ) CONST PURE;

```

The above method is of `ID2D1RenderTarget` which is a direct base of
`ID2D1HwndRenderTarget` and where it gets inherited.

This prototype says it is a function taking only an implicit `this`
argument and returning a `D2D1_SIZE_F`.

Note that `D2D1_SIZE_F` is defined as a `struct` of two `FLOAT`s (see
'd2dbasetypes.h' from mingw-w64 or Win8 SDK and earlier, or 'dcommon.h'
from Win10 SDK):

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

This struct has 64 bits. According to MSDN it should be returned in RAX [1].


But, MSDN is wrong about member functions [2]. The online compiler shows
that it is returned by reference. The `this` argument goes into RCX, and
the pointer to uninitialized storage for the returned struct goes into RDX.

Our current definition
```
#define ID2D1HwndRenderTarget_GetSize(this)  \
        (this)->lpVtbl->Base.GetSize((ID2D1RenderTarget*)(this))
```
is an indirect call to a non-member function, so [1] is correct that the
result is returned in RAX [2].


So, yes, you are right, the mingw-w64 definitions are broken. I think
inline wrappers are necessary to work around the calling convention
problem. Patches are welcome.


[1]
https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019#return-values
[2] https://gcc.godbolt.org/z/3GyBGG


-- 
Best regards,
LH_Mouse

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to