powerpoint presentation › ... › edm › images › keynote2_visualstudio2012_se… · •...

25

Upload: others

Post on 26-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 2: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 3: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 4: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

Optimized for Windows Store

Page 5: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 6: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 7: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

ref class ref new ^

collection.h

PPL Tasks Library

property

event

delegate

partial class

Page 8: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

Defining public ref class Person {

public:

Person(String^ name);

void Greet(Person^ other);

private:

void SetPassword(const std::wstring& passwd);

std::wstring pwd;

};

Using Person^ p = ref new Person(“John Surname”);

p->Greet(ref new Person(“Jim Surname”);

• Public methods restricted to WinRT typed

parameters

• Private/internal methods can use any legal C++

type parameters

Page 9: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

• Handle (^) is a pointer to a Windows Runtime object for

which the compiler performs automatic reference

counting

• ref new instantiates or activates a Windows Runtime class

Person^ p; { Person^ p2 = ref new Person(); // refcount = 1 p2->Name = “John”; // refcount = 1 p = p2; // refcount = 2 } // refcount = 1 p = nullptr; // refcount = 0; ~Person()

Page 10: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

8. String^ str6(str1); 9. String^ str7 = str2; // using wchar_t’s 10.wchar_t msg[] = L"Test"; 11.String^ str8 = ref new

String(msg); // using wstring’s 12.std::wstring wstr1(L"Test"); 13.String^ str9 = ref new

String(wstr1.c_str()); //init wstring from String^ 14.std::wstring wstr(str1->Data());

• Platform::String^ as a boundary type

• Immutable

• Interop with std::wstring and wchar_t*

1. using namespace Platform; 2. #include <string>

// init String^ from literal 3. String^ str1 = "Test"; // no need for L 4. String^ str2("Test"); 5. String^ str3 = L"Test"; 6. String^ str4(L"Test"); 7. String^ str5 = ref new

String(L"Test");

Page 11: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

Vector Map

VectorView MapView

IVector

IVectorView

IObservable

Vector

IMap

IMapView

IObservable

Map

IIterable

IIterator

Windows Runtime

Interfaces

Concrete collection

types for C++

Page 12: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

Producing and Consuming

1. #include <vector>

2. #include <algorithm>

3. #include <utility>

4. #include <collection.h>

5. namespace WFC = Windows::Foundation::Collections;

6.

7. WFC::IVectorView<int>^ Producer() {

8. std::vector<int> v;

9. v.push_back(1);

10. v.push_back(2);

11.

12. return ref new Platform::VectorView<int>(std::move(v));

13. }

14.

15. int sum = 0;

16. WFC::IVectorView<int>^ v = Producer();

17. std::for_each(begin(v), end(v), [&sum](int i) { sum += i; });

• WinRT objects are

STL friendly

• WinRT collections

are STL friendly

• STL containers are

the backing

stores for C++

collections

Page 13: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

PPL tasks simplify async Windows Runtime programming

StorageFolder^ item = KnownFolders::PicturesLibrary; StorageFileRetrievalOperation^ createStorageFileOp = item->CreateFileAsync("myfile.txt"); createStorageFileOp->Completed = ref new AsyncOperationCompletedHandler<StorageFile^>( [](IAsyncOperation<StorageFile^>^ asyncOp) { StorageFile^ storageFile = asyncOp->GetResults(); }); createStorageFileOp->Start();

StorageFolder^ item = KnownFolders::PicturesLibrary; task<StorageFile^> (item->CreateFileAsync("myfile.txt")).then([](StorageFile^ createdFile) {});

Without PPL tasks

With PPL tasks

Page 14: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

• Properties: provide a flexible mechanism to read, write, or

compute the value of a private field

• Delegates: A type that safely encapsulates a method,

similar to a function pointer in C and C++.

• Events: enable a class or object to notify other classes or

objects when something of interest occurs

Page 15: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 16: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 17: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 18: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 19: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 20: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic

C++ WinRT Component

Extension SDKs

Page 21: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 22: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 23: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic
Page 25: PowerPoint Presentation › ... › edm › images › Keynote2_VisualStudio2012_Se… · • Handle (^) is a pointer to a Windows Runtime object for which the compiler performs automatic