Minimal C++/CX WinStore style app RRS feed

  • Question

  • Hello.

    What is a code for minimal app should be? By minimal I mean traditionally MsgBox from Win32/WinForms.

    My view


    #include "FrameworkView.h"
    using namespace Platform;
    using namespace Windows::ApplicationModel::Core;
    ref class FrameworkViewSource sealed : IFrameworkViewSource 
    	virtual IFrameworkView ^CreateView();
    int __cdecl main(Array<String ^> ^args)
    	FrameworkViewSource ^ViewSource = ref new FrameworkViewSource();
    	return 0;
    IFrameworkView ^FrameworkViewSource::CreateView()
    	return ref new FrameworkView();


    #pragma once
    #include <agile.h>
    enum class ActivationEntryPoint
    ref class FrameworkView sealed : public Windows::ApplicationModel::Core::IFrameworkView
    	virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView ^applicationView);
    	virtual void SetWindow(Windows::UI::Core::CoreWindow ^window);
    	virtual void Load(Platform::String ^entryPoint);
    	virtual void Run();
    	virtual void Uninitialize();
    	void OnAppActivated(Windows::ApplicationModel::Core::CoreApplicationView ^applicationView,
    		Windows::ApplicationModel::Activation::IActivatedEventArgs ^args);
    	ActivationEntryPoint m_activationEntryPoint;
    	Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
    	Platform::Agile<Windows::ApplicationModel::Core::CoreApplicationView> m_applicationView;


    #include "FrameworkView.h"
    #include <ppltasks.h>
    using namespace Platform;
    using namespace Windows::Foundation;
    using namespace Windows::UI::Core;
    using namespace Windows::UI::Popups;
    using namespace Windows::ApplicationModel::Core;
    using namespace Windows::ApplicationModel::Activation;
    using namespace concurrency;
    FrameworkView::FrameworkView() : m_activationEntryPoint(ActivationEntryPoint::Unknown)
    void FrameworkView::Initialize(CoreApplicationView ^applicationView)
    	m_applicationView = applicationView;
    	m_applicationView -> Activated += 
    		ref new TypedEventHandler<CoreApplicationView ^, IActivatedEventArgs ^>(this, &FrameworkView::OnAppActivated);
    void FrameworkView::SetWindow(CoreWindow ^window)
    	m_window = window;
    void FrameworkView::Load(String ^entryPoint)
    	if(entryPoint == "Win8UI_Hello.App")
    		m_activationEntryPoint = ActivationEntryPoint::AppInitialized;
    void FrameworkView::OnAppActivated(CoreApplicationView ^applicationView, IActivatedEventArgs ^args)
    	// Activate the application window, making it visible and enabling it to receive events.
    	CoreWindow::GetForCurrentThread() -> Activate();
    void FrameworkView::Run()
    	if(m_activationEntryPoint == ActivationEntryPoint::AppInitialized)
    		bool bRunning = true;
    		MessageDialog ^msgDia = ref new MessageDialog("Hello Windows 8!", "Here message for you");
    		Windows::UI::Core::CoreDispatcher ^dispatcher = CoreWindow::GetForCurrentThread() -> Dispatcher;
    		dispatcher -> RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal,
    			ref new Windows::UI::Core::DispatchedHandler(
    			[msgDia, &bRunning]{
    				task<IUICommand ^> m_msgDiaShow = task<IUICommand ^>(msgDia -> ShowAsync());
    				m_msgDiaShow.then([&bRunning](IUICommand ^)
    					bRunning = false;
    		while (bRunning)
    void FrameworkView::Uninitialize()

    App do not exit, even when bRunning changed to the false.

    VS warn me that

    \FrameworkView.cpp(62): warning C4451: 'FrameworkView::Run::<lambda_2b01b31fed691210cebdf1387eabb30c>::msgDia' : Usage of ref class 'Windows::UI::Popups::MessageDialog' inside this context can lead to invalid marshaling of object across contexts
    1>          Consider using 'Platform::Agile<Windows::UI::Popups::MessageDialog>' instead

    Finnaly certification failled too.

    In minimal C++/CX XAML we can just write msgDia->ShowAsync() after Initialization in main page, but in case up that be the error Access denied.

    Thanks for your attention.

    Wednesday, February 6, 2013 10:41 PM

All replies

  • Hi,

    I try to debug your codes and found that there should be other settings in project for Windows Store App.

    I would suggest you to copy your codes into this sample and reduce the DX codes.

    Best regards,

    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.

    Friday, February 8, 2013 6:54 AM
  • Thanks for response Jesse Jiang.

    My fault that I do not provide consist of Visual C++ .sln, .vcxproj, .vcxproj.filters, .vcxproj.user files and specific for Windows 8 Edition of IDE - Package.appxmanifest.
    I do not comment about .pfx file, because it critical only for signing, but not for running the app on debug machine.

    Actually solution and project based on modification version of Media engine native C++ video playback sample
    What modification I mean? Well, in root folder of project located *.cpp, *.h files, Assets folder, OutPut Directory -> $(ProjectDir)..\bin\$(Platform)\$(Configuration)\, Intermediate Directory -> ..\trash\$(Platform)\$(Configuration)\, and msvc11 folder with solutions and projects files.

    I view that construction of Visual C++ project in book Advanced 2D Game Developent by Jonathan Harbour and highly recommended this modification of project to all Visual C++ programmers.
    But unfortunately this modification do not work with C++/CX XAML project: because .g.h/.g.cpp files generated and linker do not find correct paths.

    I do that you ask - copy the code to the project Input: Manipulations and gestures (C++) sample and modification cpp filers to use pch.h and entry point to defined in project.
    <strike>Link to SkyDrive (contains both projects).</strike>Removed during future discussion.

    While building the same message

    1>  frameworkview.cpp(54): warning C4451: 
    'FrameworkView::Run::<lambda_8cb60daac2902c2230d22ac5e5425195>::msgDia' : Usage of ref class 
    'Windows::UI::Popups::MessageDialog' inside this context can lead to invalid marshaling of object across contexts
    1>          Consider using 'Platform::Agile<Windows::UI::Popups::MessageDialog>' instead

    By the way, while running both projects I see that message in VS:

    First-chance exception at 0x75E24B32 (KernelBase.dll) in GestureRecognizerSample.exe: 0x40080201: WinRT originate error (parameters: 0x80004005, 0x00000026, 0x036CF644).

    Thanks for your time and attention.

    • Edited by TheViceMan Monday, February 25, 2013 9:29 AM Remove link to SkyDrive
    Friday, February 8, 2013 1:19 PM
  • I think it may be because the Message loop for the application is just getting started and showing a message dialog can lead to problems. The following link should help understand the sequence of the IFrameworkView events and their description.


    You can try adding that MessageDialog at some later stage where the application has initialized completely.


    Tuesday, February 19, 2013 6:31 PM
  • Thanks for link Sagar B. Joshi.
    Early I do during Phil Napieralski - Developing a Windows Store app using C++ and DirectX
    From that construction I do next
    void FrameworkView::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
     MessageDialog ^msgDia = ref new MessageDialog("Here the message for you.", "Hello Windows8!");
     msgDia -> ShowAsync();

    No debug warning and run-time exception.
    Monday, February 25, 2013 9:21 AM