locked
instantiating a SpriteBatch object when my DeviceContext is a ComPtr

    Question

  • This question has to do with the DirecXTK library that Chuck Walbourn & Shawn Hargreaves put together. I'm using c++,  VS11 Ultimate beta, and win 8 CP to make a metro app.

    The SpriteBatch takes a pointer to the deviceContext as an argument in the constructor:

    explicit SpriteBatch(_In_ ID3D11DeviceContext* deviceContext);

    However, using the Direct3DApplication starter project, it creates the ID3D11deviceContext using a ComPtr:

    Microsoft::WRL::ComPtr<ID3D11DeviceContext>    m_d3dContext;

    So when I try the line from Shawn's Blog,:

    std::unique_ptr<SpriteBatch> spriteBatch(new SpriteBatch(m_d3dContext));

    I get a red squiggly under the 'left paren' between the words SpiteBatch & the m_d3dContext. The compile error says this:

    cannot convert parameter 1 from 'Microsoft::WRL::ComPtr<T>' to 'ID3D11DeviceContext *'

    I'm a little too new at c++ and pointers to know how to resolve this, but I bet there's an easy answer. How would I go about converting the pointers to give the SpriteBatch constructor what it wants?

    Thank you.


    • Edited by Shazen Saturday, April 28, 2012 10:53 PM
    Saturday, April 28, 2012 10:53 PM

Answers

  • hi, you need the underlying interface pointer

    m_d3dContex.Get( );

    • Marked as answer by Shazen Sunday, April 29, 2012 11:45 AM
    Sunday, April 29, 2012 10:40 AM

All replies

  • hi, you need the underlying interface pointer

    m_d3dContex.Get( );

    • Marked as answer by Shazen Sunday, April 29, 2012 11:45 AM
    Sunday, April 29, 2012 10:40 AM
  • Thank you so much. That worked.
    Sunday, April 29, 2012 11:45 AM