On Saturday, 3 December 2016 at 09:51:00 UTC, John C wrote:
Some DirectX methods return structs by value, but when I try calling them I either get garbage or an access violation.

Usually COM methods return structs by pointer as a parameter, but these are returning the struct as the actual return value, as in this definition:

  extern(Windows):
  struct D2D1_SIZE_F { float width, height; }

  interface ID2D1Bitmap : ID2D1Image {
    D2D1_SIZE_F GetSize();
  }

If I rewrite GetSize to return by pointer as a parameter, it appears to work and I get the correct width and height without an AV being thrown. And I can add a helper method that returns by value:

  interface ID2D1Bitmap : ID2D1Image {
    void GetSize(D2D1_SIZE_F* size);

    final D2D1_SIZE_F GetSize() {
      D2D1_SIZE_F size;
      GetSize(&size);
      return size;
    }
  }

But does anyone know why the original definition works in C++ but not D? Is it a bug? (I'm compiling with -m64.)

most likely due to this
https://issues.dlang.org/show_bug.cgi?id=16527

and that is annoying. i tried ldc2 1.1.beta6 and dmd 2.072.1 both x86 and x64 and it crashes anyways, sooner or later.

btw if you make call with return pointer instead of value it can probably messed up your stack already and crash any moment later.

in my DirectX bindings i used to return ref struct(though i think this is dirty hack), and it was working until recent.

Reply via email to