factory.c 3.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 *	ClassFactory implementation for DEVENUM.dll
 *
 * Copyright (C) 2002 John K. Hohm
 * Copyright (C) 2002 Robert Shearman
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23 24 25 26 27 28 29 30
 */

#include "devenum_private.h"

#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(devenum);

/**********************************************************************
 * DEVENUM_IClassFactory_QueryInterface (also IUnknown)
 */
31 32
static HRESULT WINAPI DEVENUM_IClassFactory_QueryInterface(IClassFactory *iface, REFIID riid,
    void **ppvObj)
33
{
34
    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppvObj);
35

36
    if (ppvObj == NULL) return E_POINTER;
37 38 39 40

    if (IsEqualGUID(riid, &IID_IUnknown) ||
	IsEqualGUID(riid, &IID_IClassFactory))
    {
41
        *ppvObj = iface;
42 43 44 45 46 47 48 49
	IClassFactory_AddRef(iface);
	return S_OK;
    }
    else if (IsEqualGUID(riid, &IID_IParseDisplayName))
    {
        return IClassFactory_CreateInstance(iface, NULL, riid, ppvObj);
    }

50
    FIXME("- no interface IID: %s\n", debugstr_guid(riid));
51 52 53 54 55 56
    return E_NOINTERFACE;
}

/**********************************************************************
 * DEVENUM_IClassFactory_AddRef (also IUnknown)
 */
57
static ULONG WINAPI DEVENUM_IClassFactory_AddRef(IClassFactory *iface)
58 59 60
{
    TRACE("\n");

61
    DEVENUM_LockModule();
62

63
    return 2; /* non-heap based object */
64 65 66 67 68
}

/**********************************************************************
 * DEVENUM_IClassFactory_Release (also IUnknown)
 */
69
static ULONG WINAPI DEVENUM_IClassFactory_Release(IClassFactory *iface)
70 71 72
{
    TRACE("\n");

73
    DEVENUM_UnlockModule();
74

75
    return 1; /* non-heap based object */
76 77 78 79 80
}

/**********************************************************************
 * DEVENUM_IClassFactory_CreateInstance
 */
81 82
static HRESULT WINAPI DEVENUM_IClassFactory_CreateInstance(IClassFactory *iface,
        IUnknown *pUnkOuter, REFIID riid, void **ppvObj)
83
{
84
    TRACE("(%p)->(%p, %s, %p)\n", iface, pUnkOuter, debugstr_guid(riid), ppvObj);
85

86
    if (ppvObj == NULL) return E_POINTER;
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

    /* Don't support aggregation (Windows doesn't) */
    if (pUnkOuter != NULL) return CLASS_E_NOAGGREGATION;

    if (IsEqualGUID(&IID_ICreateDevEnum, riid))
    {
        *ppvObj = &DEVENUM_CreateDevEnum;
        return S_OK;
    }
    if (IsEqualGUID(&IID_IParseDisplayName, riid))
    {
        *ppvObj = &DEVENUM_ParseDisplayName;
        return S_OK;
    }

    return CLASS_E_CLASSNOTAVAILABLE;
}

/**********************************************************************
 * DEVENUM_IClassFactory_LockServer
 */
108
static HRESULT WINAPI DEVENUM_IClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
109 110 111
{
    TRACE("\n");

112 113 114 115
    if (fLock)
        DEVENUM_LockModule();
    else
        DEVENUM_UnlockModule();
116 117 118 119 120 121
    return S_OK;
}

/**********************************************************************
 * IClassFactory_Vtbl
 */
122
static const IClassFactoryVtbl IClassFactory_Vtbl =
123 124 125 126 127 128 129 130 131 132 133
{
    DEVENUM_IClassFactory_QueryInterface,
    DEVENUM_IClassFactory_AddRef,
    DEVENUM_IClassFactory_Release,
    DEVENUM_IClassFactory_CreateInstance,
    DEVENUM_IClassFactory_LockServer
};

/**********************************************************************
 * static ClassFactory instance
 */
134
ClassFactoryImpl DEVENUM_ClassFactory = { { &IClassFactory_Vtbl } };