metro style apps from c++ developers' view

Click here to load reader

Post on 14-May-2015




2 download

Embed Size (px)


  • 1. C++ Metro Style App (ericsk) Technical EvangelistMicrosoft

2. C++/CX Metro Style App Win32 API COM AMP GPU 3. C++ (?) C/C++ (?) C/C++-based library Using SQLite in a Metro Style App 4. Windows 8 5. Windows 8 6. C++/CX 7. Metro Style App C++ C++/CX (Component Extensions) Metro Style App ( WinRT Component) C++11 STL desktop app C++11 C++/CLI Reference count (namespace) WinRT 8. Metro Style App C++/CX// C++/CX auto message = ref new Platform::String(L"Hello, world");// auto dialog = ref new Windows::UI::Popups::MessageDialog(message);// dialog->ShowAsync(); WinRT Component 9. C++11 IAsyncOperation^>^Class1::DoSomethingAsync(String^ uri, IMap^parameters){auto params = make_shared();params->uri = uri->Data();Type interfacefor_each(begin(parameters), end(parameters), [params](IKeyValuePair^ value) {params->parameters.push_back(tuple(value->Key->Data(), value->Value->ToString()->Data()));}); lambda function....} 10. C++/CX native code C++/CLI CLI IL codeC++/CX Power/Performance-efficiency metro style app x86, x64 ARM app package 11. METRO STYLE APPS(WINRT) 12. XAML UI C++ Button^ b = ref new Button();b->Name = L"MyButton";b->Width = 80;b->Height = 50;b->Content = L"Click"; Blend VS Visual Designer 13. DEMO: METRO STYLE APP 14. WinRT Component Metro Style App Win32 API COM (Language Projection) C++/C#/ WinRT component metro style app build .dll/.winmd metro style app 15. Windows Runtime #pragma once namespace WindowsRuntimeComponent1 { public ref class Class1 sealed { public: Class1(); Platform::String^ SayHello() { auto hello = ref new Platform::String(L"Hello!"); return hello; } }; } sealed 16. Hybrid Metro Style App Metro Style App (Add References) app WinRT component API // JavaScript var compo = new WindowsRuntimeComponent1.Class1(); // JavaScript camel case style var helloStr = compo.sayHello(); .dll .winmd 17. DEMO: WINRT COMPONENT 18. WIN32 API COM 19. Win32 API COM Win32 API COM Metro Style App WACK : #pragma region Application Family#pragma region Desktop Family 20. COM Windows Runtime C++ Template Library (WRL)ComPtr ptr;HRESULT hr = CoCreateInstanceEx(CLSID_XXX...);if (FAILED(hr)){// process error} COM IInspectable Microsoft::WRL::Details::RuntimeClass COM 21. : MSXML// IXMLHttpRequest2Callback class HttpRequestCallback: publicRuntimeClass, IXMLHTTPRequest2Callback, FtmBase>{...// IFACEMETHODIMPOnResponseReceived(IXMLHTTPRequest2*, ISequentialStream*pResponseStream){...}...} 22. : MSXML ()// COMComPtr xhr;// HRESULT hr =CoCreateInstance(CLSID_XmlHttpRequest, nullptr, CLSCTX_INPROC, IID_PPV_ARGS(&xhr));if (FAILED(hr)){// }// callback auto callback = Make(xhr.Get(), cancellationToken);...// callbackhr = xhr->Open(method.c_str(), uri.c_str(), callback.Get(), nullptr, nullptr, nullptr, nullptr);...// requesthr = xhr->Send(nullptr, 0); 23. DEMO: MSXML6 COM 24. AMP 25. AMP Accelerated Massive Parallelism PPL CPU AMP GPU Metro Style App C++-style Library GPU 20 VS2012 Ref: 26. AMP #include concurrency array array_view extent index accelerator accelerator_viewparallel_for_each restrict Asks compiler to check your code is ok for GPU (DirectX) 27. Array void AddArrays(int n, int *#include pA, int * pB, int * pSum)using namespace concurrency;{void AddArrays(int n, int * pA, intfor (int i=0; i a(n, pA);pSum[i] = pA[i] + pB[i]; array_view b(n, pB);}array_view sum(n, pSum);} parallel_for_each( sum.extent, [=](index i) restrict(amp) { sum[i] = a[i] + b[i]; }); } 28. AMP array_view: AMP void AddArrays(int n, int * pA, int * pB, int * pSum)parallel_for_each: {lambda array_view a(n, pA);thread array_view b(n, pB); array_view sum(n, pSum); restrict(amp): compiler parallel_for_each( AMP sum.extent, [=](index i) restrict(amp)extent: thread { sum[i] = a[i] + b[i]; }); }array_view GPU index: thread 29. AMP No No recursion goto or labeled statementsthrow, try, catch volatileglobals or statics virtual functions dynamic_cast or typeid pointers to functions asm declarations pointers to membervarargsfunctions unsupported types e.g. char, short, long pointers in structs double pointers to pointers bitfields 30. DEMO: MATRIXMULTIPLICATION 31. C++ C/C++ (?) C/C++-based library Using SQLite in a Metro Style App AMP GPU COM DirectX 11 32. Visual C++ Language Reference (C++/CX) Developing Windows 8 Metro style apps with C++ Win32 and COM API AMP MSDN Library Concurrency Blog Developing games Visual C++ Team Blog