locked
VS 2012 - DirectX objects used in 'sub'classes

    Question

  • Hi there!

    My Manager class derives from the DirectXBase class:

    ref class MyManager sealed : public DirectXBase

    so that the DirectX dependend objects (d2dDevice etc.) are created.

    (Same like the new created Direct2D Project from VS2012)

     

    Now i have some classes that should draw "themselves" to the d2dContext.

    But it's not possible to pass this classes the d2dDevice as a param in the render method


    not possible by design of the WinRT:

    void Render(Microsoft::WRL::ComPtr<ID2D1Device> m_d2dContext);

    error C3986: 'Render':  signature of member contains native type 'Microsoft::WRL::ComPtr<T>'

    void Render(ID2D1Device *m_d2dContext); // same Thing as above

    or i'm not allowed to use the private protected m_pd2dContext of the DirectXBase/Manager class,


    but how is it possible to do something like this?:

    void Manager.Render()

    {

    xyzClass.Render(m_pd2dContext); // or

    xyzClass.Render();

    }

    Maybe it's so easy, but i don't see the solution :-(


    Thursday, June 7, 2012 7:02 PM

Answers

  • m_d2dContext is not static, you must have an instance of your class :

    public ref class Base
    {
    internal :
    
    	int m_x;
    };
    
    public ref class Derived : public Base
    {
    private :
    
    	void DoSomething( ) { m_x = 1; }
    };
    
    public ref class Extern
    {
    private :
    
    	void DoSomething( Derived^ d ) { d->m_x = 2; } 
    };
    Friday, June 8, 2012 1:28 PM

All replies

  • Hi, you can replace "protected private" by "internal".
    Thursday, June 7, 2012 11:25 PM
  • Hi, i've tried it, but it's not working :-(

    ref class DirectXBase abstract

    {

    internal:

    DirectXBase();

    Microsoft::WRL::ComPtr<ID2D1DeviceContext> m_d2dContext; // changed from protected private to internal

    ...

    public:

    virtual void Render();

    ...

    }

    and my class tries to use it like this:

    #include "pch.h"

    #include "DirectXBase.h"

    xyzClass::xyzClass()

    {

    ...

    }

    void xyzClass::Render()

    {

    m_d2dContext->SaveDrawingState(m_pStateBlock.Get());

    }

    but i get the error C2605 : 'm_d2dContext' : undeclared identifier

    and something like this

    DirectXBase::m_d2dContext->SaveDrawingState(m_pStateBlock.Get());
    

    brings the error C2227

    The whole project should be a port from XNA to C++ because of Metro, but it's driving me crazy with the VS2012 RC :-(

    Friday, June 8, 2012 8:29 AM
  • m_d2dContext is not static, you must have an instance of your class :

    public ref class Base
    {
    internal :
    
    	int m_x;
    };
    
    public ref class Derived : public Base
    {
    private :
    
    	void DoSomething( ) { m_x = 1; }
    };
    
    public ref class Extern
    {
    private :
    
    	void DoSomething( Derived^ d ) { d->m_x = 2; } 
    };
    Friday, June 8, 2012 1:28 PM
  • Thanks t-n-x!

    Now it's working, after my misunderstanding, what you really meant with your first post. The main problem was also, that i forgot the project namespaces in the extern classes, so there were still the dependence errors!

    Friday, June 8, 2012 4:27 PM