dxdiag_main.c 4.46 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
#include "config.h"
25 26 27 28 29 30 31 32 33
#include <stdarg.h>

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

WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);

39
HINSTANCE dxdiagn_instance = 0;
40

41 42
LONG DXDIAGN_refCount = 0;

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

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

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

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

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

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

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

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

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

101 102 103 104 105 106
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);
107 108
}

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

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

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

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

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

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

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

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

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

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