Authors: Robert Shearman <rob@codeweavers.com>, Mike Hearn <mh@codeweavers.com>
[wine] / dlls / dxdiagn / dxdiag_main.c
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "config.h"
23 #include "dxdiag_private.h"
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
27
28 /* At process attach */
29 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
30 {
31   TRACE("%p,%lx,%p\n", hInstDLL, fdwReason, lpvReserved);
32   if (fdwReason == DLL_PROCESS_ATTACH) {
33     DisableThreadLibraryCalls(hInstDLL);    
34   }
35   return TRUE;
36 }
37
38 /*******************************************************************************
39  * DXDiag ClassFactory
40  */
41 typedef struct {
42   /* IUnknown fields */
43   ICOM_VFIELD(IClassFactory);
44   DWORD      ref; 
45   REFCLSID   rclsid;
46   HRESULT   (*pfnCreateInstanceFactory)(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj);
47 } IClassFactoryImpl;
48
49 static HRESULT WINAPI DXDiagCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
50   ICOM_THIS(IClassFactoryImpl,iface);
51   
52   FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
53   return E_NOINTERFACE;
54 }
55
56 static ULONG WINAPI DXDiagCF_AddRef(LPCLASSFACTORY iface) {
57   ICOM_THIS(IClassFactoryImpl,iface);
58   return ++(This->ref);
59 }
60
61 static ULONG WINAPI DXDiagCF_Release(LPCLASSFACTORY iface) {
62   ICOM_THIS(IClassFactoryImpl,iface);
63   /* static class, won't be  freed */
64   return --(This->ref);
65 }
66
67 static HRESULT WINAPI DXDiagCF_CreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj) {
68   ICOM_THIS(IClassFactoryImpl,iface);
69   
70   TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
71   return This->pfnCreateInstanceFactory(iface, pOuter, riid, ppobj);
72 }
73
74 static HRESULT WINAPI DXDiagCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
75   ICOM_THIS(IClassFactoryImpl,iface);
76   FIXME("(%p)->(%d),stub!\n",This,dolock);
77   return S_OK;
78 }
79
80 static ICOM_VTABLE(IClassFactory) DXDiagCF_Vtbl = {
81   ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
82   DXDiagCF_QueryInterface,
83   DXDiagCF_AddRef,
84   DXDiagCF_Release,
85   DXDiagCF_CreateInstance,
86   DXDiagCF_LockServer
87 };
88
89 static IClassFactoryImpl DXDiag_CFS[] = {
90   { &DXDiagCF_Vtbl, 1, &CLSID_DxDiagProvider, DXDiag_CreateDXDiagProvider },
91   { NULL, 0, NULL, NULL }
92 };
93
94 /***********************************************************************
95  *             DllCanUnloadNow (DXDIAGN.@)
96  */
97 HRESULT WINAPI DllCanUnloadNow(void)
98 {
99     return S_FALSE;
100 }
101
102 /***********************************************************************
103  *              DllGetClassObject (DXDIAGN.@)
104  */
105 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
106 {
107     int i = 0;
108
109     TRACE("(%p,%p,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
110     while (NULL != DXDiag_CFS[i].rclsid) {
111       if (IsEqualGUID(rclsid, DXDiag_CFS[i].rclsid)) {
112               DXDiagCF_AddRef((IClassFactory*) &DXDiag_CFS[i]);
113               *ppv = &DXDiag_CFS[i];
114               return S_OK;
115       }
116       ++i;
117     }
118
119     FIXME("(%p,%p,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
120     return CLASS_E_CLASSNOTAVAILABLE;
121 }