dxdiag_main.c 4.25 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 70 71 72 73 74 75 76 77 78
  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);
  else {
    FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
    *ppv = NULL;
    return E_NOINTERFACE;
  }

  *ppv = iface;
  IClassFactory_AddRef(iface);
  return S_OK;
79 80
}

81 82
static ULONG WINAPI DXDiagCF_AddRef(IClassFactory *iface)
{
83 84 85
  DXDIAGN_LockModule();

  return 2; /* non-heap based object */
86 87
}

88 89
static ULONG WINAPI DXDiagCF_Release(IClassFactory * iface)
{
90 91 92
  DXDIAGN_UnlockModule();

  return 1; /* non-heap based object */
93 94
}

95 96 97 98 99 100
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);
101 102
}

103 104
static HRESULT WINAPI DXDiagCF_LockServer(IClassFactory *iface, BOOL dolock)
{
105 106 107 108 109 110 111
  TRACE("(%d)\n", dolock);

  if (dolock)
    DXDIAGN_LockModule();
  else
    DXDIAGN_UnlockModule();
  
112 113 114
  return S_OK;
}

115
static const IClassFactoryVtbl DXDiagCF_Vtbl = {
116 117 118 119 120 121 122
  DXDiagCF_QueryInterface,
  DXDiagCF_AddRef,
  DXDiagCF_Release,
  DXDiagCF_CreateInstance,
  DXDiagCF_LockServer
};

123
static IClassFactoryImpl DXDiag_CF = { { &DXDiagCF_Vtbl } };
124 125

/***********************************************************************
126
 *             DllCanUnloadNow (DXDIAGN.@)
127 128 129
 */
HRESULT WINAPI DllCanUnloadNow(void)
{
130
  return DXDIAGN_refCount != 0 ? S_FALSE : S_OK;
131 132 133
}

/***********************************************************************
134
 *		DllGetClassObject (DXDIAGN.@)
135 136 137
 */
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
138
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
139 140 141 142 143

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

146
    FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
147 148
    return CLASS_E_CLASSNOTAVAILABLE;
}
149 150 151 152 153 154

/***********************************************************************
 *		DllRegisterServer (DXDIAGN.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
155
    return __wine_register_resources( dxdiagn_instance );
156 157 158 159 160 161 162
}

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