Returning structs from COM

kinke via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 19 14:47:26 PST 2016


On Monday, 19 December 2016 at 09:49:13 UTC, kinke wrote:
> That's rather interesting. The COM function really seems to 
> return the struct directly, not returning an HRESULT and 
> setting some output pointee as most COM functions I've seen so 
> far. According to the Win64 ABI, the returned D2D1_SIZE_F 
> struct should be returned in RAX, as the 2 floats are <= 64 
> bit. But your workaround seems to suggest it's using sret 
> (struct-return via hidden pointer). To make sure this is the 
> case, I'd suggest inspecting the C++ assembly for a trivial 
> function. If so, we'll need to find out why the Win64 ABI isn't 
> followed and whether COM has its own ABI.

I did some research myself and indeed, COM classes/interfaces are 
apparently subject to a separate ABI. Unfortunately, googling it 
hasn't turned up any official (and not even some inofficial) 
documentation so far. Based on the first few tests on Win64, 
integers are returned in RAX, floats (and I guess doubles too) in 
XMM0, and structs (incl. 2x int32 and 2x float) via hidden sret 
pointer, with `this` pointer in RCX (1st arg) and `sret` in RDX 
(2nd arg). Compared to the normal Win64 C++ ABI it just seems 
more conservative by always returning structs via hidden pointer.


More information about the Digitalmars-d-learn mailing list