dxdiag_main.c 4.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* 
 * DXDiag
 * 
 * Copyright 2004 Raphael Junqueira
 *
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21
 *
 */

22 23
#define COBJMACROS

24 25 26 27 28 29 30 31 32
#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "oleauto.h"
#include "oleidl.h"
#include "rpcproxy.h"
#include "initguid.h"
33 34 35 36 37
#include "dxdiag_private.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);

38
HINSTANCE dxdiagn_instance = 0;
39

40 41
LONG DXDIAGN_refCount = 0;

42 43 44
/* At process attach */
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
45
  TRACE("%p,%x,%p\n", hInstDLL, fdwReason, lpvReserved);
46
  if (fdwReason == DLL_PROCESS_ATTACH) {
47
      dxdiagn_instance = hInstDLL;
48
      DisableThreadLibraryCalls(hInstDLL);
49 50 51 52 53 54 55 56
  }
  return TRUE;
}

/*******************************************************************************
 * DXDiag ClassFactory
 */
typedef struct {
57
  IClassFactory IClassFactory_iface;
58 59
} IClassFactoryImpl;

60 61
static HRESULT WINAPI DXDiagCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
62 63
  if (ppv == NULL)
    return E_POINTER;
64

65 66 67 68
  if (IsEqualGUID(&IID_IUnknown, riid))
    TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
  else if (IsEqualGUID(&IID_IClassFactory, riid))
    TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
69 70 71 72 73 74
  else if (IsEqualGUID(&IID_IExternalConnection, riid) ||
           IsEqualGUID(&IID_IMarshal, riid)) {
    TRACE("(%p)->(%s) ignoring\n", iface, debugstr_guid(riid));
    *ppv = NULL;
    return E_NOINTERFACE;
  }
75 76 77 78 79 80 81 82 83
  else {
    FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
    *ppv = NULL;
    return E_NOINTERFACE;
  }

  *ppv = iface;
  IClassFactory_AddRef(iface);
  return S_OK;
84 85
}

86 87
static ULONG WINAPI DXDiagCF_AddRef(IClassFactory *iface)
{
88 89 90
  DXDIAGN_LockModule();

  return 2; /* non-heap based object */
91 92
}

93 94
static ULONG WINAPI DXDiagCF_Release(IClassFactory * iface)
{
95 96 97
  DXDIAGN_UnlockModule();

  return 1; /* non-heap based object */
98 99
}

100 101 102 103 104 105
static HRESULT WINAPI DXDiagCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid,
        void **ppv)
{
  TRACE("(%p)->(%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid), ppv);

  return DXDiag_CreateDXDiagProvider(iface, pOuter, riid, ppv);
106 107
}

108 109
static HRESULT WINAPI DXDiagCF_LockServer(IClassFactory *iface, BOOL dolock)
{
110 111 112 113 114 115 116
  TRACE("(%d)\n", dolock);

  if (dolock)
    DXDIAGN_LockModule();
  else
    DXDIAGN_UnlockModule();
  
117 118 119
  return S_OK;
}

120
static const IClassFactoryVtbl DXDiagCF_Vtbl = {
121 122 123 124 125 126 127
  DXDiagCF_QueryInterface,
  DXDiagCF_AddRef,
  DXDiagCF_Release,
  DXDiagCF_CreateInstance,
  DXDiagCF_LockServer
};

128
static IClassFactoryImpl DXDiag_CF = { { &DXDiagCF_Vtbl } };
129 130

/***********************************************************************
131
 *             DllCanUnloadNow (DXDIAGN.@)
132 133 134
 */
HRESULT WINAPI DllCanUnloadNow(void)
{
135
  return DXDIAGN_refCount != 0 ? S_FALSE : S_OK;
136 137 138
}

/***********************************************************************
139
 *		DllGetClassObject (DXDIAGN.@)
140 141 142
 */
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
143
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
144 145 146 147 148

    if (IsEqualGUID(rclsid, &CLSID_DxDiagProvider)) {
      IClassFactory_AddRef(&DXDiag_CF.IClassFactory_iface);
      *ppv = &DXDiag_CF.IClassFactory_iface;
      return S_OK;
149 150
    }

151
    FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
152 153
    return CLASS_E_CLASSNOTAVAILABLE;
}
154 155 156 157 158 159

/***********************************************************************
 *		DllRegisterServer (DXDIAGN.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
160
    return __wine_register_resources( dxdiagn_instance );
161 162 163 164 165 166 167
}

/***********************************************************************
 *		DllUnregisterServer (DXDIAGN.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
168
    return __wine_unregister_resources( dxdiagn_instance );
169
}