atl80: Added AtlComModuleRegisterServer implementation (based on AtlModuleRegisterSer...
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  */
21
22 #define COBJMACROS
23
24 #include "config.h"
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "objbase.h"
30 #include "oleauto.h"
31 #include "oleidl.h"
32 #include "rpcproxy.h"
33 #include "initguid.h"
34 #include "dxdiag_private.h"
35 #include "wine/debug.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
38
39 HINSTANCE dxdiagn_instance = 0;
40
41 LONG DXDIAGN_refCount = 0;
42
43 /* At process attach */
44 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
45 {
46   TRACE("%p,%x,%p\n", hInstDLL, fdwReason, lpvReserved);
47   if (fdwReason == DLL_PROCESS_ATTACH) {
48       dxdiagn_instance = hInstDLL;
49       DisableThreadLibraryCalls(hInstDLL);
50   }
51   return TRUE;
52 }
53
54 /*******************************************************************************
55  * DXDiag ClassFactory
56  */
57 typedef struct {
58   IClassFactory IClassFactory_iface;
59 } IClassFactoryImpl;
60
61 static HRESULT WINAPI DXDiagCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
62 {
63   if (ppv == NULL)
64     return E_POINTER;
65
66   if (IsEqualGUID(&IID_IUnknown, riid))
67     TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
68   else if (IsEqualGUID(&IID_IClassFactory, riid))
69     TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
70   else {
71     FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
72     *ppv = NULL;
73     return E_NOINTERFACE;
74   }
75
76   *ppv = iface;
77   IClassFactory_AddRef(iface);
78   return S_OK;
79 }
80
81 static ULONG WINAPI DXDiagCF_AddRef(IClassFactory *iface)
82 {
83   DXDIAGN_LockModule();
84
85   return 2; /* non-heap based object */
86 }
87
88 static ULONG WINAPI DXDiagCF_Release(IClassFactory * iface)
89 {
90   DXDIAGN_UnlockModule();
91
92   return 1; /* non-heap based object */
93 }
94
95 static HRESULT WINAPI DXDiagCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid,
96         void **ppv)
97 {
98   TRACE("(%p)->(%p,%s,%p)\n", iface, pOuter, debugstr_guid(riid), ppv);
99
100   return DXDiag_CreateDXDiagProvider(iface, pOuter, riid, ppv);
101 }
102
103 static HRESULT WINAPI DXDiagCF_LockServer(IClassFactory *iface, BOOL dolock)
104 {
105   TRACE("(%d)\n", dolock);
106
107   if (dolock)
108     DXDIAGN_LockModule();
109   else
110     DXDIAGN_UnlockModule();
111   
112   return S_OK;
113 }
114
115 static const IClassFactoryVtbl DXDiagCF_Vtbl = {
116   DXDiagCF_QueryInterface,
117   DXDiagCF_AddRef,
118   DXDiagCF_Release,
119   DXDiagCF_CreateInstance,
120   DXDiagCF_LockServer
121 };
122
123 static IClassFactoryImpl DXDiag_CF = { { &DXDiagCF_Vtbl } };
124
125 /***********************************************************************
126  *             DllCanUnloadNow (DXDIAGN.@)
127  */
128 HRESULT WINAPI DllCanUnloadNow(void)
129 {
130   return DXDIAGN_refCount != 0 ? S_FALSE : S_OK;
131 }
132
133 /***********************************************************************
134  *              DllGetClassObject (DXDIAGN.@)
135  */
136 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
137 {
138     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
139
140     if (IsEqualGUID(rclsid, &CLSID_DxDiagProvider)) {
141       IClassFactory_AddRef(&DXDiag_CF.IClassFactory_iface);
142       *ppv = &DXDiag_CF.IClassFactory_iface;
143       return S_OK;
144     }
145
146     FIXME("(%s,%s,%p): no interface found.\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
147     return CLASS_E_CLASSNOTAVAILABLE;
148 }
149
150 /***********************************************************************
151  *              DllRegisterServer (DXDIAGN.@)
152  */
153 HRESULT WINAPI DllRegisterServer(void)
154 {
155     return __wine_register_resources( dxdiagn_instance );
156 }
157
158 /***********************************************************************
159  *              DllUnregisterServer (DXDIAGN.@)
160  */
161 HRESULT WINAPI DllUnregisterServer(void)
162 {
163     return __wine_unregister_resources( dxdiagn_instance );
164 }