Namespaces and Type visibility - const strings in C++


  • Hello,

    My game consists of an Application project, and a Windows Runtime Component.  The component defines a list of constant strings, however the App project cannot see it.  How do I need to declare these strings such that they are defined in the metadata, and can be used across ABI?

    namespace Gaia
    	namespace MessageType
    		Platform::String^ const ButtonDown = "Gaia.ButtonDown";
    		Platform::String^ const ButtonTapped = "Gaia.ButtonTapped";
    		Platform::String^ const ButtonUp = "Gaia.ButtonUp";
    		Platform::String^ const GameStateBecomingActive = "Gaia.GameStateBecomingActive";
    		Platform::String^ const GameStateBecomingInactive = "Gaia.GameStateBecomingInactive";
    		Platform::String^ const GameStateActive = "Gaia.GameStateActive";
    		Platform::String^ const GameStateInactive = "Gaia.GameStateInactive";
    		Platform::String^ const TouchEventDragged = "Gaia.TouchEventDragged";
    		Platform::String^ const TouchEventHeld = "Gaia.TouchEventHeld";
    		Platform::String^ const TouchEventPressed = "Gaia.TouchEventPressed";
    		Platform::String^ const TouchEventReleased = "Gaia.TouchEventReleased";

    Land Of Simeria - http://www.stormsonggames.com/los

    • Edited by bkinsey Friday, October 26, 2012 7:32 PM
    Friday, October 26, 2012 7:31 PM


  • Hi,

    In Windows Runtime, only class struct enum, delegate and interface can be public under the namespace. The const value cannot.

    We would suggest you to change const value as static property.

    	public ref class MessageType sealed
    		static property Platform::String^  ButtonDown { Platform::String^ get(){return L"Gaia.ButtonDown";} }
    		static property Platform::String^  ButtonTapped { Platform::String^ get(){return L"Gaia.ButtonTapped";}}
    		static property Platform::String^  ButtonUp { Platform::String^ get(){return L"Gaia.ButtonUp";} }
    		static property Platform::String^  GameStateBecomingActive { Platform::String^ get(){return L"Gaia.GameStateBecomingActive";} }
    		static property Platform::String^  GameStateBecomingInactive { Platform::String^ get(){return L"Gaia.GameStateBecomingInactive";} }
    		static property Platform::String^  GameStateActive { Platform::String^ get(){return L"Gaia.GameStateActive";} }
    		static property Platform::String^  GameStateInactive { Platform::String^ get(){return L"Gaia.GameStateInactive";} }
    		static property Platform::String^  TouchEventDragged { Platform::String^ get(){return L"Gaia.TouchEventDragged";} }
    		static property Platform::String^  TouchEventHeld { Platform::String^ get(){return L"Gaia.TouchEventHeld";} }
    		static property Platform::String^  TouchEventPressed { Platform::String^ get(){return L"Gaia.TouchEventPressed";} }
    		static property Platform::String^  TouchEventReleased { Platform::String^ get(){return L"Gaia.TouchEventReleased";} }

    Best regards,

    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Jesse Jiang Wednesday, October 31, 2012 3:03 AM
    • Marked as answer by Jesse Jiang Thursday, November 1, 2012 6:52 AM
    Monday, October 29, 2012 7:28 AM