Quick Recap • WinRT • Visual C++ Component Extensions Windows Core OS Services.

Download Report

Transcript Quick Recap • WinRT • Visual C++ Component Extensions Windows Core OS Services.

Quick Recap
• WinRT
• Visual C++ Component Extensions
Windows Core OS Services
Set of language extensions and libraries to allow direct consumption and authoring of
Windows Runtime types.
1. delegate void CarouselInitDoneHandler IUIAnimationVariable^ rotation
2.
3. void CarouselAnimation::Initialize(double angle, CarouselInitDoneHandler^ callback) {
4.
// Create Animation Manager
5.
using namespace Engine::Graphics;
6.
UIAnimationManager animationManager();
7.
// Create rotation animation variable
8.
IUIAnimationVariable^ rotation = animationManager.CreateAnimationVariable(angle);
9.
// Set the event handler for the story board
10.
rotation->GetCurrentStoryBoard()
11.
->SetStoryBoardEventHandler(
12.
ref new CarouselStoryBoardHandler(this, &CarouselAnimation::StoryBoard)
13.
);
14.
// Invoke the callback when done
15.
callback(rotation);
16.}
Microsoft Confidential
11/6/2015
6
String^
1.
2.
using namespace Platform;
#include <string>
3.
4.
5.
6.
7.
8.
9.
10.
// initializing a String^
String^ str1 = "Test"; // no need for L
String^ str2("Test");
String^ str3 = L"Test";
String^ str4(L"Test");
String^ str5 = ref new String(L"Test");
String^ str6(str1);
String^ str7 = str2;
11. wchar_t msg[] = L"Test";
12. String^ str8 = ref new String(msg);
13. std::wstring wstr1(L"Test");
14. String^ str9 = ref new String(wstr1.c_str());
15. String^ str10 = ref new String(wstr1.c_str(), wstr1.length());
1.
2.
3.
// initializing a std::wstring from String^
std::wstring wstr2(str1->Data());
std::wstring wstr3(str1->Data(), str1->Length());
4.
5.
6.
7.
8.
//
if
if
if
if
comparisons
(str1 == str2) { /* ... */ }
(str1 != str2) { /* ... */ }
(str1 < str2) { /* ... */ }
(str1 < "test") { /* ... */ }
Exception^
HRESULT
E_OUTOFMEMORY
E_INVALIDARG
E_NOINTERFACE
E_POINTER
E_NOTIMPL
E_ACCESSDENIED
E_FAIL
E_BOUNDS
E_CHANGED_STATE
REGDB_E_CLASSNOTREG
E_DISCONNECTED
E_ABORT
Exception
OutOfMemoryException
InvalidArgumentException
InvalidCastException
NullReferenceException
NotImplementedException
AccessDeniedException
FailureException
OutOfBoundsException
ChangedStateException
ClassNotRegisteredException
DisconnectedException
OperationCanceledException
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
using namespace Platform;
try
{
if (filename == "") { throw ref new InvalidArgumentException(); }
auto pics = Windows::Storage::KnownFolders::PicturesLibrary;
auto res = pics->GetFilesAsync();
}
catch (InvalidArgumentException^ e) { /* same as E_INVALIDARG */ }
catch (NullReferenceException^ e)
{ /* same as E_POINTER */ }
catch (AccessDeniedException^ e)
{ /* same as E_ACCESSDENIED */ }
catch (FailureException^ e)
{ /* same as E_FAIL */ }
void main() {
try {
ModuleB::Apple();
}
catch (Platform::FailureException^) {
ModuleB::Orange();
}
}
void Pear() {
// perform out-of-bounds operation
}
E_FAIL
E_BOUNDS
void Apple() {
throw ref new
Platform::FailureException();
}
void Orange() {
try {
ModuleA::Pear();
}
catch
(Platform::OutOfBoundsException^) {
}
}
Collections
IIterable
IIterator
• STL containers are the backing store
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
#include <vector>
#include <algorithm>
#include <utility>
#include <collection.h>
namespace WFC = Windows::Foundation::Collections;
WFC::IVectorView<int>^ Producer() {
std::vector<int> v;
v.push_back(1);
v.push_back(2);
return ref new Platform::VectorView<int>(std::move(v));
}
int sum = 0;
WFC::IVectorView<int>^ v = Producer();
std::for_each(begin(v), end(v), [&sum](int i) { sum += i; });
Async pattern
1. void main()
2. {
3.
// create the async operation, but don’t start it
4.
SomeOperation^ someOp = Operation();
5.
6.
// define what happens when the operation completes
7.
someOp->Completed = ref new AsyncOperationCompletedHandler<SomeType^>
8.
([](IAsyncOperation<SomeType^>^ asyncOp) {
9.
// do whatever you want with the result after the operation has completed
10.
auto result = asyncOp->GetResults();
11.
}
12.
13.
// invoke the async operation
14.
someOp->Start();
15. }
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
using namespace Windows::Storage;
using namespace Windows::Foundation;
void main () {
auto op = KnownFolders::PicturesLibrary->GetItemsAsync();
op->Completed = ref new AsyncOperationCompletedHandler<IVectorView<IStorageItem^>^>(
[](IAsyncOperation<IVectorView<IStorageItem^>^>^ op)
{
auto items = op->GetResults();
});
op->Start();
}
void main()
{
StorageFolder^ item = Windows::Storage::KnownFolders::PicturesLibrary;
CreateStorageFileOperation^ createStorageFileOp = item->CreateFileAsync("bar.txt");
createStorageFileOp->Completed = ref new AsyncOperationCompletedHandler<StorageFile^>(
[](IAsyncOperation<StorageFile^>^ asyncOp) {
StreamRetrievalOperation^ streamRetrievalOp = asyncOp->GetResults()->OpenAsync(FileAccessMode::ReadWrite);
streamRetrievalOp->Completed = ref new AsyncOperationCompletedHandler<IRandomAccessStream^>(
[](IAsyncOperation<IRandomAccessStream^>^ asyncOp2) {
IOutputStream^ stream = asyncOp2->GetResults()->GetOutputStreamAt(0);
BasicBinaryReaderWriter^ bbrw = ref new BasicBinaryReaderWriter();
WriteBinaryStringOperation^ writeBinaryStringOp =
bbrw->WriteBinaryStringAsync(stream, "this string gets written into the file");
writeBinaryStringOp->Completed = ref new AsyncOperationCompletedHandler<unsigned int>(
[=](IAsyncOperation<unsigned int>^ asyncOp3) {
int bytes = asyncOp3->GetResults();
IStreamFlushOperation^ streamFlushOp = stream->FlushAsync();
streamFlushOp->Completed = ref new StreamFlushCompletedEventHandler(
[](IStreamFlushOperation^ asyncOp4) {
bool result = asyncOp4->GetResults();
});
streamFlushOp->Start();
});
writeBinaryStringOp->Start();
});
streamRetrievalOp->Start();
});
createStorageFileOp->Start();
}
26
http://go.microsoft.com/fwlink/?LinkId=228286
1. void SomeClass::InvokeOperation()
2. {
3.
// create the async operation, but don’t start it
4.
auto someOp = OperationAsync();
5.
task<SomeType^> t(someOp);
6.
6.
// define what happens when the operation completes
7.
t.then ([](SomeType^ opResult) {
9.
// do whatever you want with the result after the operation has completed
10.
});
11.
12.
// no need to manually “start” the async operation
13. }
28
1. void SomeClass::InvokeOperation()
2. {
3.
StorageFolder^ item = Windows::Storage::KnownFolders::PicturesLibrary;
4.
StorageFile
("bar.txt"))
5.
shared_ptr<IOutputStream^> ostream = make_shared<IOutputStream^>(nullptr);
6.
// use a shared pointer to ensure the stream is valid after function exits
7.
t.then([](StorageFile^ storageFile) {
8.
return storageFile->OpenAsync(FileAccessMode::ReadWrite);
9.
}).then([=](IRandomAccessStream^ rastream) -> StringBinaryAsyncOperation {
10.
*ostream = rastream->GetOutputStreamAt(0);
11.
BasicBinaryReaderWriter^ bbrw = ref new BasicBinaryReaderWriter();
12.
return bbrw->WriteBinaryStringAsync(ostream, "this string gets written into the file");
13.
}).then([=](unsigned int bytesWritten) {
14.
return (*ostream)->FlushAsync();
15.
}).then([](bool flushed) {
16.
// all done!
17.
});
29
18. }
Win32
•
•
•
•
COM Core
Kernel
Accessibility
Audio
•
•
•
•
•
Direct2D
Direct3D
DirectComposition
DirectManipulation
DirectWrite
•
•
•
•
File Systems
Globalization
Media Foundation
Windows and Messages
1. void
2.
3.
wicBitmap, wicFactory, scaler, FlipRotator;
4.
5.
hr = CoCreateInstance (CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
6.
IID_IWICImagingFactory, &wicFactory);
7.
if (SUCCEEDED(hr))
8.
hr = wicFactory->CreateDecoderFromFilename
9.
(wFileName->Data(),nullptr,GENERIC_READ,WICDecodeMetadataCacheOnLoad,&decoder);
10.
if (SUCCEEDED(hr))
11.
hr = decoder->GetFrame (0, &bitmapSource);
12.
if(SUCCEEDED(hr))
13.
hr = bitmapSource.As (&wicBitmap);
14.
if(SUCCEEDED(hr))
15.
GetImageSize();
16.
; // if fail, throw the most specific Exception^ type
17. }
32
[TOOL-479T]
[TOOL-532T]
[TOOL-690C]
[TOOL-789C]
[TOOL-802T]
[TOOL-835T]
http://go.microsoft.com/fwlink/?LinkID=227459
http://go.microsoft.com/fwlink/?LinkId=228286
[email protected]
Questions?
http://forums.dev.windows.com
http://bldw.in/SessionFeedback
Useful Resources
Metro style Apps
Core
System Services
Model
Controller
View
XAML
C
C++
Desktop Apps
HTML / CSS
C#
VB
JavaScript
(Chakra)
HTML
C
C++
C#
VB
Internet
Explorer
Win32
.NET
/ SL
JavaScript
WinRT APIs
Communication
& Data
Graphics &
Media
Application Model
Devices &
Printing
Windows Core OS Services