Search code examples
c++directxdrawtext

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


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()
    );

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.