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 HINSTANCE wshom_instance
;
31 static ITypeLib
*typelib
;
32 static ITypeInfo
*typeinfos
[LAST_tid
];
34 static REFIID tid_ids
[] = {
42 static HRESULT
load_typelib(void)
47 hres
= LoadRegTypeLib(&LIBID_IWshRuntimeLibrary
, 1, 0, LOCALE_SYSTEM_DEFAULT
, &tl
);
49 ERR("LoadRegTypeLib failed: %08x\n", hres
);
53 if(InterlockedCompareExchangePointer((void**)&typelib
, tl
, NULL
))
58 HRESULT
get_typeinfo(tid_t tid
, ITypeInfo
**typeinfo
)
63 hres
= load_typelib();
70 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, tid_ids
[tid
], &ti
);
72 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids
[tid
]), hres
);
76 if(InterlockedCompareExchangePointer((void**)(typeinfos
+tid
), ti
, NULL
))
77 ITypeInfo_Release(ti
);
80 *typeinfo
= typeinfos
[tid
];
81 ITypeInfo_AddRef(*typeinfo
);
86 void release_typelib(void)
93 for(i
=0; i
< sizeof(typeinfos
)/sizeof(*typeinfos
); i
++)
95 ITypeInfo_Release(typeinfos
[i
]);
97 ITypeLib_Release(typelib
);
100 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
104 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
105 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
107 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
108 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
113 IUnknown_AddRef((IUnknown
*)*ppv
);
117 FIXME("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
118 return E_NOINTERFACE
;
121 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
123 TRACE("(%p)\n", iface
);
127 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
129 TRACE("(%p)\n", iface
);
133 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
135 TRACE("(%p)->(%x)\n", iface
, fLock
);
139 static const IClassFactoryVtbl WshShellFactoryVtbl
= {
140 ClassFactory_QueryInterface
,
142 ClassFactory_Release
,
143 WshShellFactory_CreateInstance
,
144 ClassFactory_LockServer
147 static IClassFactory WshShellFactory
= { &WshShellFactoryVtbl
};
149 /******************************************************************
150 * DllMain (wshom.ocx.@)
152 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
154 TRACE("(%p %d %p)\n", hInstDLL
, fdwReason
, lpv
);
158 case DLL_WINE_PREATTACH
:
159 return FALSE
; /* prefer native version */
160 case DLL_PROCESS_ATTACH
:
161 wshom_instance
= hInstDLL
;
162 DisableThreadLibraryCalls(wshom_instance
);
164 case DLL_PROCESS_DETACH
:
173 /***********************************************************************
174 * DllGetClassObject (wshom.ocx.@)
176 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
178 if(IsEqualGUID(&CLSID_WshShell
, rclsid
)) {
179 TRACE("(CLSID_WshShell %s %p)\n", debugstr_guid(riid
), ppv
);
180 return IClassFactory_QueryInterface(&WshShellFactory
, riid
, ppv
);
183 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
184 return CLASS_E_CLASSNOTAVAILABLE
;
187 /***********************************************************************
188 * DllCanUnloadNow (wshom.ocx.@)
190 HRESULT WINAPI
DllCanUnloadNow(void)
195 /***********************************************************************
196 * DllRegisterServer (wshom.ocx.@)
198 HRESULT WINAPI
DllRegisterServer(void)
201 return __wine_register_resources(wshom_instance
);
204 /***********************************************************************
205 * DllUnregisterServer (wshom.ocx.@)
207 HRESULT WINAPI
DllUnregisterServer(void)
210 return __wine_unregister_resources(wshom_instance
);