summaryrefslogtreecommitdiff
path: root/wpd/WpdWudfSampleDriver/helpers.h
blob: d2e2cf18b23672ebc063faeb641b1098b48b7740 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#pragma once

#define FAKE_DATA_SIZE          (5 * 1024 * 1024 + 1831)
#define OPTIMAL_BUFFER_SIZE     (2 * 1024 * 1024)

// {9b2dce3f-cf02-4643-ae09-2bcf0012ac6d}
DEFINE_GUID(FakeContent_Format, 0x9b2dce3f, 0xcf02, 0x4643, 0xae, 0x09, 0x2b, 0xcf, 0x00, 0x12, 0xac, 0x6d);
// {8E829938-D838-479E-8489-5EC84986EE3B}
DEFINE_GUID(FakeDeviceContent_Format, 0x8E829938, 0xD838, 0x479E, 0x84, 0x89, 0x5E, 0xC8, 0x49, 0x86, 0xEE, 0x3B);
// {BDC7BBF8-3AAC-458F-92C9-7CD236186552}
DEFINE_GUID(FakeStorageContent_Format, 0xBDC7BBF8, 0x3AAC, 0x458F, 0x92, 0xC9, 0x7C, 0xD2, 0x36, 0x18, 0x65, 0x52);
//  We will define a custom format for memo objects: {C6F2ECC0-C351-42D6-AE20-837CE1EF433C}
DEFINE_GUID(FakeMemoContent_Format, 0xC6F2ECC0, 0xC351, 0x42D6, 0xAE, 0x20, 0x83, 0x7C, 0xE1, 0xEF, 0x43, 0x3C);

// {4DF6C8C7-2CE5-457C-9F53-EFCECAA95C04}
DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, 0x4DF6C8C7, 0x2CE5, 0x457C, 0x9F, 0x53, 0xEF, 0xCE, 0xCA, 0xA9, 0x5C, 0x04, 2);
// {CDD18979-A7B0-4D5E-9EB2-0A826805CBBD}
DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, 0xCDD18979, 0xA7B0, 0x4D5E, 0x9E, 0xB2, 0x0A, 0x82, 0x68, 0x05, 0xCB, 0xBD, 2);
// {9BD949E5-59CF-41AE-90A9-BE1D044F578F}
DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, 0x9BD949E5, 0x59CF, 0x41AE, 0x90, 0xA9, 0xBE, 0x1D, 0x04, 0x4F, 0x57, 0x8F, 2);

#ifndef SAFE_RELEASE
    #define SAFE_RELEASE(p) if( NULL != p ) { ( p )->Release(); p = NULL; }
#endif

typedef enum tagFakeDevicePropertyAttributesType
{
    UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast,
    UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast,
} FakeDevicePropertyAttributesType;

typedef struct tagKeyAndAttributesEntry
{
    const GUID*                         pFormat;
    const PROPERTYKEY*                  pKey;
    FakeDevicePropertyAttributesType    type;
} KeyAndAttributesEntry;

HRESULT AddFixedAttributesByType(
            FakeDevicePropertyAttributesType AttributesType,
    _In_    IPortableDeviceValues*           pAttributes);

HRESULT AddFixedPropertyAttributes(
    _In_    REFGUID                         guidObjectFormat,
    _In_    REFPROPERTYKEY                  key,
    _In_    IPortableDeviceValues*          pAttributes);

HRESULT AddSupportedProperties(
    _In_            REFGUID                         guidObjectFormatOrCategory,
    _COM_Outptr_    IPortableDeviceKeyCollection**  ppKeys);

HRESULT AddSupportedProperties(
    _In_    REFGUID                        guidObjectFormatOrCategory,
    _In_    IPortableDeviceKeyCollection*  pKeys);

HRESULT SetRenderingProfiles(
    _In_    IPortableDeviceValues*          pValues);

HRESULT AddExtraSupportedProperties(
    _In_    LPCWSTR                         pszObjectID,
    _In_    IPortableDeviceKeyCollection*   pKeys);

HRESULT AddExtraPropertyValues(
    _In_    LPCWSTR                         pszObjectID,
    _In_    IPortableDeviceValues*          pValues);

DWORD GetResourceSize(
    UINT uiResource);

PBYTE GetResourceData(
    UINT uiResource);

HRESULT IsValidContentType(
    _In_    REFGUID             guidObjectContentType,
    _In_    CAtlArray<GUID>&    RestrictedTypes);

HRESULT GetClientContext(
    _In_            IPortableDeviceValues*  pParams,
    _In_            LPCWSTR                 pszContextKey,
    _COM_Outptr_    IUnknown**              ppContext);

HRESULT GetClientEventCookie(
    _In_                      IPortableDeviceValues*  pParams,
    _Outptr_result_maybenull_ LPWSTR*       ppszEventCookie);

HRESULT PostWpdEvent(
    _In_    IPortableDeviceValues*  pCommandParams,
    _In_    IPortableDeviceValues*  pEventParams);

HRESULT PostWpdEventWithProgress(
    _In_    IPortableDeviceValues*  pCommandParams,
    _In_    IPortableDeviceValues*  pEventParams,
    _In_    REFGUID                 guidEvent,
            const DWORD             dwOperationState,
            const DWORD             dwOperationProgress);

BOOL ExistsInCollection(_In_ REFGUID guid, _In_ IPortableDevicePropVariantCollection* pCollection);

class PropVariantWrapper : public tagPROPVARIANT
{
public:
    PropVariantWrapper()
    {
        PropVariantInit(this);
    }

    PropVariantWrapper(_In_ LPCWSTR pszSrc)
    {
        PropVariantInit(this);

        *this = pszSrc;
    }

    virtual ~PropVariantWrapper()
    {
        Clear();
    }

    void Clear()
    {
        PropVariantClear(this);
    }

    PropVariantWrapper& operator= (ULONG ulValue)
    {
        Clear();
        vt      = VT_UI4;
        ulVal   = ulValue;

        return *this;
    }

    PropVariantWrapper& operator= (_In_ LPCWSTR pszSrc)
    {
        Clear();

        pwszVal = AtlAllocTaskWideString(pszSrc);
        if(pwszVal != NULL)
        {
            vt = VT_LPWSTR;
        }
        return *this;
    }

    PropVariantWrapper& operator= (_In_ IUnknown* punkSrc)
    {
        Clear();

        // Need to AddRef as PropVariantClear will Release
        if (punkSrc != NULL)
        {
            vt      = VT_UNKNOWN;
            punkVal = punkSrc;
            punkVal->AddRef();
        }
        return *this;
    }

    void SetErrorValue(HRESULT hr)
    {
        Clear();
        vt      = VT_ERROR;
        scode   = hr;
    }

    void SetBoolValue(bool bValue)
    {
        Clear();
        vt      = VT_BOOL;
        if(bValue)
        {
            boolVal = VARIANT_TRUE;
        }
        else
        {
            boolVal = VARIANT_FALSE;
        }
    }
};

HRESULT CreateVCard(_In_ IPortableDeviceValues* pValues, _Out_ CAtlStringA& strVCard);

HRESULT UpdateDeviceFriendlyName(
    _In_    IPortableDeviceClassExtension*  pPortableDeviceClassExtension,
    _In_    LPCWSTR                         wszDeviceFriendlyName);

HRESULT GetCommonResourceAttributes(
    _COM_Outptr_    IPortableDeviceValues** ppAttributes);