dxdiag_main.c 4.24 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
 *
 */

#include "config.h"
23 24 25 26 27 28 29 30 31
#include <stdarg.h>

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

WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);

37 38
static HINSTANCE instance;

39 40
LONG DXDIAGN_refCount = 0;

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

/*******************************************************************************
 * DXDiag ClassFactory
 */
typedef struct {
56
  const IClassFactoryVtbl *lpVtbl;
57 58 59 60 61
  REFCLSID   rclsid;
  HRESULT   (*pfnCreateInstanceFactory)(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj);
} IClassFactoryImpl;

static HRESULT WINAPI DXDiagCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
62 63 64
  FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));

  if (ppobj == NULL) return E_POINTER;
65 66 67 68 69
  
  return E_NOINTERFACE;
}

static ULONG WINAPI DXDiagCF_AddRef(LPCLASSFACTORY iface) {
70 71 72
  DXDIAGN_LockModule();

  return 2; /* non-heap based object */
73 74 75
}

static ULONG WINAPI DXDiagCF_Release(LPCLASSFACTORY iface) {
76 77 78
  DXDIAGN_UnlockModule();

  return 1; /* non-heap based object */
79 80 81
}

static HRESULT WINAPI DXDiagCF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
82
  IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
83
  TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
84
  
85 86 87 88
  return This->pfnCreateInstanceFactory(iface, pOuter, riid, ppobj);
}

static HRESULT WINAPI DXDiagCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
89 90 91 92 93 94 95
  TRACE("(%d)\n", dolock);

  if (dolock)
    DXDIAGN_LockModule();
  else
    DXDIAGN_UnlockModule();
  
96 97 98
  return S_OK;
}

99
static const IClassFactoryVtbl DXDiagCF_Vtbl = {
100 101 102 103 104 105 106 107
  DXDiagCF_QueryInterface,
  DXDiagCF_AddRef,
  DXDiagCF_Release,
  DXDiagCF_CreateInstance,
  DXDiagCF_LockServer
};

static IClassFactoryImpl DXDiag_CFS[] = {
108 109
  { &DXDiagCF_Vtbl, &CLSID_DxDiagProvider, DXDiag_CreateDXDiagProvider },
  { NULL, NULL, NULL }
110 111 112
};

/***********************************************************************
113
 *             DllCanUnloadNow (DXDIAGN.@)
114 115 116
 */
HRESULT WINAPI DllCanUnloadNow(void)
{
117
  return DXDIAGN_refCount != 0 ? S_FALSE : S_OK;
118 119 120
}

/***********************************************************************
121
 *		DllGetClassObject (DXDIAGN.@)
122 123 124 125 126
 */
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
    int i = 0;

127
    TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
128 129 130 131 132 133 134 135 136
    while (NULL != DXDiag_CFS[i].rclsid) {
      if (IsEqualGUID(rclsid, DXDiag_CFS[i].rclsid)) {
	      DXDiagCF_AddRef((IClassFactory*) &DXDiag_CFS[i]);
	      *ppv = &DXDiag_CFS[i];
	      return S_OK;
      }
      ++i;
    }

137
    FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
138 139
    return CLASS_E_CLASSNOTAVAILABLE;
}
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

/***********************************************************************
 *		DllRegisterServer (DXDIAGN.@)
 */
HRESULT WINAPI DllRegisterServer(void)
{
    return __wine_register_resources( instance, NULL );
}

/***********************************************************************
 *		DllUnregisterServer (DXDIAGN.@)
 */
HRESULT WINAPI DllUnregisterServer(void)
{
    return __wine_unregister_resources( instance, NULL );
}