2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wshom_private.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(wshom
);
29 static inline struct provideclassinfo
*impl_from_IProvideClassInfo(IProvideClassInfo
*iface
)
31 return CONTAINING_RECORD(iface
, struct provideclassinfo
, IProvideClassInfo_iface
);
34 static ITypeLib
*typelib
;
35 static ITypeInfo
*typeinfos
[LAST_tid
];
37 static REFIID tid_ids
[] = {
47 static HRESULT
load_typelib(void)
55 hres
= LoadRegTypeLib(&LIBID_IWshRuntimeLibrary
, 1, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
57 ERR("LoadRegTypeLib failed: %#lx.\n", hres
);
61 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
66 static HRESULT
get_typeinfo_of_guid(const GUID
*guid
, ITypeInfo
**tinfo
)
70 if(FAILED(hres
= load_typelib()))
73 return ITypeLib_GetTypeInfoOfGuid(typelib
, guid
, tinfo
);
76 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
80 if (FAILED(hres
= load_typelib()))
86 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
88 ERR("GetTypeInfoOfGuid(%s) failed: %#lx.\n", debugstr_guid(tid_ids
[tid
]), hres
);
92 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
93 ITypeInfo_Release(ti
);
96 *typeinfo
= typeinfos
[tid
];
97 ITypeInfo_AddRef(*typeinfo
);
102 void release_typelib(void)
109 for(i
= 0; i
< ARRAY_SIZE(typeinfos
); i
++)
111 ITypeInfo_Release(typeinfos
[i
]);
113 ITypeLib_Release(typelib
);
116 static HRESULT WINAPI
provideclassinfo_QueryInterface(IProvideClassInfo
*iface
, REFIID riid
, void **obj
)
118 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
120 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
122 if (IsEqualIID(riid
, &IID_IProvideClassInfo
)) {
124 IProvideClassInfo_AddRef(iface
);
128 return IUnknown_QueryInterface(This
->outer
, riid
, obj
);
131 static ULONG WINAPI
provideclassinfo_AddRef(IProvideClassInfo
*iface
)
133 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
134 return IUnknown_AddRef(This
->outer
);
137 static ULONG WINAPI
provideclassinfo_Release(IProvideClassInfo
*iface
)
139 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
140 return IUnknown_Release(This
->outer
);
143 static HRESULT WINAPI
provideclassinfo_GetClassInfo(IProvideClassInfo
*iface
, ITypeInfo
**ti
)
145 struct provideclassinfo
*This
= impl_from_IProvideClassInfo(iface
);
147 TRACE("(%p)->(%p)\n", This
, ti
);
149 return get_typeinfo_of_guid(This
->guid
, ti
);
152 static const IProvideClassInfoVtbl provideclassinfovtbl
= {
153 provideclassinfo_QueryInterface
,
154 provideclassinfo_AddRef
,
155 provideclassinfo_Release
,
156 provideclassinfo_GetClassInfo
159 void init_classinfo(const GUID
*guid
, IUnknown
*outer
, struct provideclassinfo
*classinfo
)
161 classinfo
->IProvideClassInfo_iface
.lpVtbl
= &provideclassinfovtbl
;
162 classinfo
->outer
= outer
;
163 classinfo
->guid
= guid
;
166 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
170 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
171 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
173 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
174 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
179 IUnknown_AddRef((IUnknown
*)*ppv
);
183 WARN("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
184 return E_NOINTERFACE
;
187 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
189 TRACE("(%p)\n", iface
);
193 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
195 TRACE("(%p)\n", iface
);
199 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
201 TRACE("(%p)->(%x)\n", iface
, fLock
);
205 static const IClassFactoryVtbl WshShellFactoryVtbl
= {
206 ClassFactory_QueryInterface
,
208 ClassFactory_Release
,
209 WshShellFactory_CreateInstance
,
210 ClassFactory_LockServer
213 static const IClassFactoryVtbl WshNetworkFactoryVtbl
= {
214 ClassFactory_QueryInterface
,
216 ClassFactory_Release
,
217 WshNetworkFactory_CreateInstance
,
218 ClassFactory_LockServer
221 static IClassFactory WshShellFactory
= { &WshShellFactoryVtbl
};
222 static IClassFactory WshNetworkFactory
= { &WshNetworkFactoryVtbl
};
224 /******************************************************************
225 * DllMain (wshom.ocx.@)
227 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
229 TRACE("%p, %ld, %p.\n", hInstDLL
, fdwReason
, lpv
);
233 case DLL_PROCESS_ATTACH
:
234 DisableThreadLibraryCalls(hInstDLL
);
236 case DLL_PROCESS_DETACH
:
245 /***********************************************************************
246 * DllGetClassObject (wshom.ocx.@)
248 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
250 if(IsEqualGUID(&CLSID_WshShell
, rclsid
)) {
251 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid
), ppv
);
252 return IClassFactory_QueryInterface(&WshShellFactory
, riid
, ppv
);
254 else if(IsEqualGUID(&CLSID_WshNetwork
, rclsid
)) {
255 TRACE("(CLSID_WshNetwork %s %p)\n", debugstr_guid(riid
), ppv
);
256 return IClassFactory_QueryInterface(&WshNetworkFactory
, riid
, ppv
);
259 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
260 return CLASS_E_CLASSNOTAVAILABLE
;