What is the difference between “ [in] const D2D1_RECT_F *layoutRect”' and 'const D2D1_RECT_F &layoutRect,' in DirectX Api

StackOverflow https://stackoverflow.com//questions/20031968

  •  21-12-2019
  •  | 
  •  

Question

I'm trying to run the method ID2D1RenderTarget::DrawText method, and my current error is related to the argument types I'm passing. (See code below)

I believe the issue is that my 'Rect1' argument meets the criteria given here http://msdn.microsoft.com/en-us/library/windows/desktop/dd371919%28v=vs.85%29.aspx where i've passed "const D2D1_RECT_F &layoutRect"

However on closer inspection I should be using this API: http://msdn.microsoft.com/en-us/library/windows/desktop/dd371916%28v=vs.85%29.aspx where I am required to pass "[in] const D2D1_RECT_F *layoutRect"

So my question is, what is the difference between the two? And if you're feeling extra generous how can I fix my argument to pass the argument above instead.

Any help greatly appreciated, cheers!

My code:

D2D1_RECT_F Rect1 = D2D1::RectF(60.0f, 90.0f, 80.0f, 60.0f);
devcon2d->DrawText (
    sc_score,
    ARRAYSIZE(sc_score)-1,
    dtextformat,
    Rect1,
    pBlackBrush.Get()
    );
Was it helpful?

Solution

Just add &, like this

D2D1_RECT_F Rect1 = D2D1::RectF(60.0f, 90.0f, 80.0f, 60.0f);
devcon2d->DrawText (
    sc_score,
    ARRAYSIZE(sc_score)-1,
    dtextformat,
    &Rect1,
    pBlackBrush.Get()
    );

The first is a reference, the second is a pointer.

OTHER TIPS

Since you also asked for the difference between the two, the [in] const D2D1_RECT_F * API is the one that is actually exposed by the COM interface ID2D1RenderTarget. The reference functions are convenience functions added for the benefit of the C++ folk (which end up making the pointer call).

This is a fairly common pattern for a lot of DirectX functions; if you dig into D2D1.h you'll see more examples of functions that have convenience wrappers declared for them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top