locked
Holding WinRT data in c++ class

    Question

  • I am working on a cross-platform image editing application. We already have c++ interfaces for various things. Now, the problem is that non-WINRT c++ classes can not hold winRT data. So, how can we do it?

    We want to do something like this:

    class Window
    {
    
    public:
    virtual void Activate() = 0;
    
    };
    
    class WinRTWindow: public Window
    {
    //Hold and cache the current window
    CoreWindow ^mWindow;
    public:
    virtual void Activate()
    {
    mWindow->Activate;
    }
    }

    If we can do something like this, then the caller code will be uneffected, since it is already working on the Window interface.

    Please help.

    Tuesday, April 16, 2013 12:15 PM

Answers

All replies

  • Hi,

    You should create Windows Runtime Component. This template included the namespace of Windows Runtime, so that we can use it in this codes

    using namespace Windows::UI::Core;
    namespace WindowsRuntimeComponent1
    {
    	class Window
    	{
    
    	public:
    		virtual void Activate() = 0;
    
    	};
    
    
    	class WinRTWindow: public Window
    	{
    		//Hold and cache the current window
    		CoreWindow ^mWindow;
    	public:
    		virtual void Activate()
    		{
    			mWindow->Activate();
    		}
    	};
    
    }

    Best regards,
    Jesse



    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Tuesday, April 23, 2013 5:44 AM
    Wednesday, April 17, 2013 6:24 AM
  • Thanks,
    But, how can we expose WinRTWindow class to the callers from a winRT component? I guess we will have to create a ref class, which will defeat the whole purpose.
    Wednesday, April 17, 2013 6:30 AM

  • Yes, the public class in Windows Runtime Component must be ref class.

    If you want to create a DLL can be used in Windows Store and Win32, you can take a look of this thread
    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/3df4f1cb-9e9f-4843-87f5-d9bdee031846

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Jesse Jiang Monday, April 22, 2013 3:06 AM
    • Marked as answer by Jesse Jiang Tuesday, April 23, 2013 5:44 AM
    Thursday, April 18, 2013 2:41 AM