xref: /reactos/dll/directx/wine/dxdiagn/dxdiag_main.c (revision 84ccccab)
1 /*
2  * DXDiag
3  *
4  * Copyright 2004 Raphael Junqueira
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 "dxdiag_private.h"
23 
24 #include <rpcproxy.h>
25 
26 HINSTANCE dxdiagn_instance = 0;
27 
28 LONG DXDIAGN_refCount = 0;
29 
30 /* At process attach */
31 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
32 {
33   TRACE("%p,%x,%p\n", hInstDLL, fdwReason, lpvReserved);
34   if (fdwReason == DLL_PROCESS_ATTACH) {
35       dxdiagn_instance = hInstDLL;
36       DisableThreadLibraryCalls(hInstDLL);
37   }
38   return TRUE;
39 }
40 
41 /*******************************************************************************
42  * DXDiag ClassFactory
43  */
44 typedef struct {
45   IClassFactory IClassFactory_iface;
46 } IClassFactoryImpl;
47 
48 static HRESULT WINAPI DXDiagCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
49 {
50   if (ppv == NULL)
51     return E_POINTER;
52 
53   if (IsEqualGUID(&IID_IUnknown, riid))
54     TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
55   else if (IsEqualGUID(&IID_IClassFactory, riid))
56     TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
57   else if (IsEqualGUID(&IID_IExternalConnection, riid) ||
58            IsEqualGUID(&IID_IMarshal, riid)) {
59     TRACE("(%p)->(%s) ignoring\n", iface, debugstr_guid(riid));
60     *ppv = NULL;
61     return E_NOINTERFACE;
62   }
63   else {
64     FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
65     *ppv = NULL;
66     return E_NOINTERFACE;
67   }
68 
69   *ppv = iface;
70   IClassFactory_AddRef(iface);
71   return S_OK;
72 }
73 
74 static ULONG WINAPI DXDiagCF_AddRef(IClassFactory *iface)
75 {
76   DXDIAGN_LockModule();
77 
78   return 2; /* non-heap based object */
79 }
80 
81 static ULONG WINAPI DXDiagCF_Release(IClassFactory * iface)
82 {
83   DXDIAGN_UnlockModule();
84 
85   return 1; /* non-heap based object */
86 }
87 
88 static HRESULT WINAPI DXDiagCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid,
89         void **ppv)
90 {
91   TRACE("(%p)->(%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid), ppv);
92 
93   return DXDiag_CreateDXDiagProvider(iface, pOuter, riid, ppv);
94 }
95 
96 static HRESULT WINAPI DXDiagCF_LockServer(IClassFactory *iface, BOOL dolock)
97 {
98   TRACE("(%d)\n", dolock);
99 
100   if (dolock)
101     DXDIAGN_LockModule();
102   else
103     DXDIAGN_UnlockModule();
104 
105   return S_OK;
106 }
107 
108 static const IClassFactoryVtbl DXDiagCF_Vtbl = {
109   DXDiagCF_QueryInterface,
110   DXDiagCF_AddRef,
111   DXDiagCF_Release,
112   DXDiagCF_CreateInstance,
113   DXDiagCF_LockServer
114 };
115 
116 static IClassFactoryImpl DXDiag_CF = { { &DXDiagCF_Vtbl } };
117 
118 /***********************************************************************
119  *             DllCanUnloadNow (DXDIAGN.@)
120  */
121 HRESULT WINAPI DllCanUnloadNow(void)
122 {
123   return DXDIAGN_refCount != 0 ? S_FALSE : S_OK;
124 }
125 
126 /***********************************************************************
127  *		DllGetClassObject (DXDIAGN.@)
128  */
129 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
130 {
131     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
132 
133     if (IsEqualGUID(rclsid, &CLSID_DxDiagProvider)) {
134       IClassFactory_AddRef(&DXDiag_CF.IClassFactory_iface);
135       *ppv = &DXDiag_CF.IClassFactory_iface;
136       return S_OK;
137     }
138 
139     FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
140     return CLASS_E_CLASSNOTAVAILABLE;
141 }
142 
143 /***********************************************************************
144  *		DllRegisterServer (DXDIAGN.@)
145  */
146 HRESULT WINAPI DllRegisterServer(void)
147 {
148     return __wine_register_resources( dxdiagn_instance );
149 }
150 
151 /***********************************************************************
152  *		DllUnregisterServer (DXDIAGN.@)
153  */
154 HRESULT WINAPI DllUnregisterServer(void)
155 {
156     return __wine_unregister_resources( dxdiagn_instance );
157 }
158