2 * Copyright 2008 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
29 #include "jscript_classes.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(jscript
);
37 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
39 HINSTANCE jscript_hinstance
;
40 static ITypeInfo
*dispatch_typeinfo
;
42 HRESULT
get_dispatch_typeinfo(ITypeInfo
**out
)
48 if (!dispatch_typeinfo
)
50 hr
= LoadRegTypeLib(&IID_StdOle
, STDOLE_MAJORVERNUM
, STDOLE_MINORVERNUM
, STDOLE_LCID
, &typelib
);
51 if (FAILED(hr
)) return hr
;
53 hr
= ITypeLib_GetTypeInfoOfGuid(typelib
, &IID_IDispatch
, &typeinfo
);
54 ITypeLib_Release(typelib
);
55 if (FAILED(hr
)) return hr
;
57 if (InterlockedCompareExchangePointer((void**)&dispatch_typeinfo
, typeinfo
, NULL
))
58 ITypeInfo_Release(typeinfo
);
61 *out
= dispatch_typeinfo
;
65 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
69 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
70 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
72 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
73 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
78 IUnknown_AddRef((IUnknown
*)*ppv
);
82 FIXME("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
86 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
88 TRACE("(%p)\n", iface
);
92 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
94 TRACE("(%p)\n", iface
);
98 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
100 TRACE("(%p)->(%x)\n", iface
, fLock
);
110 static HRESULT WINAPI
JScriptFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
,
111 REFIID riid
, void **ppv
)
113 TRACE("(%p %s %p)\n", outer
, debugstr_guid(riid
), ppv
);
117 return CLASS_E_NOAGGREGATION
;
120 return create_jscript_object(FALSE
, riid
, ppv
);
123 static const IClassFactoryVtbl JScriptFactoryVtbl
= {
124 ClassFactory_QueryInterface
,
126 ClassFactory_Release
,
127 JScriptFactory_CreateInstance
,
128 ClassFactory_LockServer
131 static IClassFactory JScriptFactory
= { &JScriptFactoryVtbl
};
133 static HRESULT WINAPI
JScriptEncodeFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
,
134 REFIID riid
, void **ppv
)
136 TRACE("(%p %s %p)\n", outer
, debugstr_guid(riid
), ppv
);
140 return CLASS_E_NOAGGREGATION
;
143 return create_jscript_object(TRUE
, riid
, ppv
);
146 static const IClassFactoryVtbl JScriptEncodeFactoryVtbl
= {
147 ClassFactory_QueryInterface
,
149 ClassFactory_Release
,
150 JScriptEncodeFactory_CreateInstance
,
151 ClassFactory_LockServer
154 static IClassFactory JScriptEncodeFactory
= { &JScriptEncodeFactoryVtbl
};
156 /******************************************************************
157 * DllMain (jscript.@)
159 BOOL WINAPI
DllMain(HINSTANCE hInstDLL
, DWORD fdwReason
, LPVOID lpv
)
161 TRACE("(%p %ld %p)\n", hInstDLL
, fdwReason
, lpv
);
164 case DLL_PROCESS_ATTACH
:
165 DisableThreadLibraryCalls(hInstDLL
);
166 jscript_hinstance
= hInstDLL
;
170 case DLL_PROCESS_DETACH
:
172 if (dispatch_typeinfo
) ITypeInfo_Release(dispatch_typeinfo
);
179 /***********************************************************************
180 * DllGetClassObject (jscript.@)
182 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
184 if(IsEqualGUID(&CLSID_JScript
, rclsid
)) {
185 TRACE("(CLSID_JScript %s %p)\n", debugstr_guid(riid
), ppv
);
186 return IClassFactory_QueryInterface(&JScriptFactory
, riid
, ppv
);
189 if(IsEqualGUID(&CLSID_JScriptEncode
, rclsid
)) {
190 TRACE("(CLSID_JScriptEncode %s %p)\n", debugstr_guid(riid
), ppv
);
191 return IClassFactory_QueryInterface(&JScriptEncodeFactory
, riid
, ppv
);
194 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
195 return CLASS_E_CLASSNOTAVAILABLE
;
198 /***********************************************************************
199 * DllCanUnloadNow (jscript.@)
201 HRESULT WINAPI
DllCanUnloadNow(void)
203 TRACE("() ref=%ld\n", module_ref
);
205 return module_ref
? S_FALSE
: S_OK
;