aboutsummaryrefslogtreecommitdiff
path: root/src/api/burn/bextutil/inc/BextBaseBootstrapperExtension.h
blob: 83ba23a6ac25ed3fe18d4b586af5a912e39cf6bf (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
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

#include <windows.h>

#include "bextutil.h"

class CBextBaseBootstrapperExtension : public IBootstrapperExtension
{
public: // IUnknown
    virtual STDMETHODIMP QueryInterface(
        __in REFIID riid,
        __out LPVOID *ppvObject
        )
    {
        if (!ppvObject)
        {
            return E_INVALIDARG;
        }

        *ppvObject = NULL;

        if (::IsEqualIID(__uuidof(IBootstrapperExtension), riid))
        {
            *ppvObject = static_cast<IBootstrapperExtension*>(this);
        }
        else if (::IsEqualIID(IID_IUnknown, riid))
        {
            *ppvObject = static_cast<IUnknown*>(this);
        }
        else // no interface for requested iid
        {
            return E_NOINTERFACE;
        }

        AddRef();
        return S_OK;
    }

    virtual STDMETHODIMP_(ULONG) AddRef()
    {
        return ::InterlockedIncrement(&this->m_cReferences);
    }

    virtual STDMETHODIMP_(ULONG) Release()
    {
        long l = ::InterlockedDecrement(&this->m_cReferences);
        if (0 < l)
        {
            return l;
        }

        delete this;
        return 0;
    }

public: // IBootstrapperExtension
    virtual STDMETHODIMP Search(
        __in LPCWSTR /*wzId*/,
        __in LPCWSTR /*wzVariable*/
        )
    {
        return E_NOTIMPL;
    }

    virtual STDMETHODIMP BootstrapperExtensionProc(
        __in BOOTSTRAPPER_EXTENSION_MESSAGE /*message*/,
        __in const LPVOID /*pvArgs*/,
        __inout LPVOID /*pvResults*/,
        __in_opt LPVOID /*pvContext*/
        )
    {
        return E_NOTIMPL;
    }

public: //CBextBaseBootstrapperExtension
    virtual STDMETHODIMP Initialize(
        __in const BOOTSTRAPPER_EXTENSION_CREATE_ARGS* pCreateArgs
        )
    {
        HRESULT hr = S_OK;

        hr = StrAllocString(&m_sczBootstrapperExtensionDataPath, pCreateArgs->wzBootstrapperExtensionDataPath, 0);
        ExitOnFailure(hr, "Failed to copy BootstrapperExtensionDataPath.");

    LExit:
        return hr;
    }

protected:

    CBextBaseBootstrapperExtension(
        __in IBootstrapperExtensionEngine* pEngine
        )
    {
        m_cReferences = 1;

        pEngine->AddRef();
        m_pEngine = pEngine;

        m_sczBootstrapperExtensionDataPath = NULL;
    }

    virtual ~CBextBaseBootstrapperExtension()
    {
        ReleaseNullObject(m_pEngine);
        ReleaseStr(m_sczBootstrapperExtensionDataPath);
    }

protected:
    IBootstrapperExtensionEngine* m_pEngine;
    LPWSTR m_sczBootstrapperExtensionDataPath;

private:
    long m_cReferences;
};