summaryrefslogtreecommitdiff
path: root/general/WinHEC 2017 Lab/Toaster Support App/App/CustomCapability/cpp/pch.cpp
blob: b300c4c08d3134e07e05b69f6b6b53fa1e665afb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

//
// pch.cpp
// Include the standard header and generate the precompiled header.
//

#include "pch.h"
#include "MainPage.xaml.h"

#include <robuffer.h>
#include <wrl\client.h>

using namespace Microsoft::WRL;
using namespace Windows::Storage::Streams;

byte* GetArrayFromBuffer(Windows::Storage::Streams::IBuffer^ buffer)
{
    ComPtr<IInspectable> base = reinterpret_cast<IInspectable*>(buffer);
    ComPtr<IBufferByteAccess> access;

    auto hr = base.As(&access);

    if (FAILED(hr))
    {
        throw Platform::Exception::CreateException(hr);
    }

    byte* data;

    hr = access->Buffer(&data);

    if (FAILED(hr))
    {
        throw Platform::Exception::CreateException(hr);
    }

    // The returned buffer is valid as long as the IBuffer passed in
    // remains valid.
    return data;
}

void NotifyStatusMessage(Platform::String^ message, SDKTemplate::NotifyType messageType)
{
    SDKTemplate::MainPage::Current->Dispatcher->RunAsync(
        Windows::UI::Core::CoreDispatcherPriority::Normal,
        ref new Windows::UI::Core::DispatchedHandler(
            [message, messageType]() {
        SDKTemplate::MainPage::Current->NotifyUser(message, messageType);
    }));
}