ReactOS  0.4.15-dev-1377-ga59cecd
scrrun.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Hans Leidekker for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18 #define COBJMACROS
19 
20 #include <stdarg.h>
21 
22 #include "windef.h"
23 #include "winbase.h"
24 #include "ole2.h"
25 #include "olectl.h"
26 #include "rpcproxy.h"
27 
28 #include <initguid.h>
29 #include "scrrun.h"
30 #include "scrrun_private.h"
31 
32 #include "wine/debug.h"
33 
35 
37 
39 {
41 }
42 
43 typedef HRESULT (*fnCreateInstance)(LPVOID *ppObj);
44 
46 {
47  *ppv = NULL;
48 
50  TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
51  *ppv = iface;
52  }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
53  TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
54  *ppv = iface;
55  }
56 
57  if(*ppv) {
58  IUnknown_AddRef((IUnknown*)*ppv);
59  return S_OK;
60  }
61 
62  WARN("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
63  return E_NOINTERFACE;
64 }
65 
67 {
68  TRACE("(%p)\n", iface);
69  return 2;
70 }
71 
73 {
74  TRACE("(%p)\n", iface);
75  return 1;
76 }
77 
79 {
80  TRACE("(%p)->(%x)\n", iface, fLock);
81  return S_OK;
82 }
83 
84 static const struct IClassFactoryVtbl scrruncf_vtbl =
85 {
91 };
92 
93 static const struct IClassFactoryVtbl dictcf_vtbl =
94 {
100 };
101 
104 
107 
108 static REFIID tid_ids[] = {
109  &IID_NULL,
110  &IID_IDictionary,
111  &IID_IDrive,
112  &IID_IDriveCollection,
113  &IID_IFile,
114  &IID_IFileCollection,
115  &IID_IFileSystem3,
116  &IID_IFolder,
117  &IID_IFolderCollection,
118  &IID_ITextStream
119 };
120 
121 static HRESULT load_typelib(void)
122 {
123  HRESULT hres;
124  ITypeLib *tl;
125 
126  if(typelib)
127  return S_OK;
128 
129  hres = LoadRegTypeLib(&LIBID_Scripting, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
130  if(FAILED(hres)) {
131  ERR("LoadRegTypeLib failed: %08x\n", hres);
132  return hres;
133  }
134 
136  ITypeLib_Release(tl);
137  return hres;
138 }
139 
141 {
142  HRESULT hres;
143 
144  if(FAILED(hres = load_typelib()))
145  return hres;
146 
147  return ITypeLib_GetTypeInfoOfGuid(typelib, guid, tinfo);
148 }
149 
151 {
152  HRESULT hres;
153 
154  if (FAILED(hres = load_typelib()))
155  return hres;
156 
157  if(!typeinfos[tid]) {
158  ITypeInfo *ti;
159 
160  hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
161  if(FAILED(hres)) {
162  ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
163  return hres;
164  }
165 
167  ITypeInfo_Release(ti);
168  }
169 
170  *typeinfo = typeinfos[tid];
171  ITypeInfo_AddRef(typeinfos[tid]);
172  return S_OK;
173 }
174 
175 static void release_typelib(void)
176 {
177  unsigned i;
178 
179  if(!typelib)
180  return;
181 
182  for (i = 0; i < ARRAY_SIZE(typeinfos); i++)
183  if(typeinfos[i])
184  ITypeInfo_Release(typeinfos[i]);
185 
186  ITypeLib_Release(typelib);
187 }
188 
190 {
192 
193  TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
194 
196  *obj = iface;
197  IProvideClassInfo_AddRef(iface);
198  return S_OK;
199  }
200  else
201  return IUnknown_QueryInterface(This->outer, riid, obj);
202 }
203 
205 {
207  return IUnknown_AddRef(This->outer);
208 }
209 
211 {
213  return IUnknown_Release(This->outer);
214 }
215 
217 {
219 
220  TRACE("(%p)->(%p)\n", This, ti);
221 
222  return get_typeinfo_of_guid(This->guid, ti);
223 }
224 
225 static const IProvideClassInfoVtbl provideclassinfovtbl = {
230 };
231 
233 {
234  classinfo->IProvideClassInfo_iface.lpVtbl = &provideclassinfovtbl;
235  classinfo->outer = outer;
236  classinfo->guid = guid;
237 }
238 
240 {
241  TRACE("%p, %u, %p\n", hinst, reason, reserved);
242 
243  switch (reason)
244  {
245  case DLL_WINE_PREATTACH:
246  return FALSE; /* prefer native version */
247  case DLL_PROCESS_ATTACH:
250  break;
251  case DLL_PROCESS_DETACH:
252  if (reserved) break;
253  release_typelib();
254  break;
255  }
256  return TRUE;
257 }
258 
259 /***********************************************************************
260  * DllRegisterServer (scrrun.@)
261  */
263 {
264  TRACE("()\n");
266 }
267 
268 /***********************************************************************
269  * DllUnregisterServer (scrrun.@)
270  */
272 {
273  TRACE("()\n");
275 }
276 
277 /***********************************************************************
278  * DllGetClassObject (scrrun.@)
279  */
280 
282 {
283  if(IsEqualGUID(&CLSID_FileSystemObject, rclsid)) {
284  TRACE("(CLSID_FileSystemObject %s %p)\n", debugstr_guid(riid), ppv);
285  return IClassFactory_QueryInterface(&FileSystemFactory, riid, ppv);
286  }
287  else if(IsEqualGUID(&CLSID_Dictionary, rclsid)) {
288  TRACE("(CLSID_Dictionary %s %p)\n", debugstr_guid(riid), ppv);
289  return IClassFactory_QueryInterface(&DictionaryFactory, riid, ppv);
290  }
291 
292  FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
294 }
295 
296 /***********************************************************************
297  * DllCanUnloadNow (scrrun.@)
298  */
300 {
301  return S_FALSE;
302 }
#define HRESULT
Definition: msvc.h:7
#define REFIID
Definition: guiddef.h:118
#define E_NOINTERFACE
Definition: winerror.h:2364
static ULONG WINAPI scrruncf_AddRef(IClassFactory *iface)
Definition: scrrun.c:66
HRESULT __wine_register_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:98
static HRESULT get_typeinfo_of_guid(const GUID *guid, ITypeInfo **tinfo)
Definition: scrrun.c:140
static ITypeInfo * typeinfos[LAST_tid]
Definition: scrrun.c:106
#define TRUE
Definition: types.h:120
REFIID riid
Definition: precomp.h:44
static HRESULT WINAPI provideclassinfo_GetClassInfo(IProvideClassInfo *iface, ITypeInfo **ti)
Definition: scrrun.c:216
#define REFCLSID
Definition: guiddef.h:117
tid_t
Definition: ieframe.h:311
#define WARN(fmt,...)
Definition: debug.h:112
REFIID LPVOID * ppv
Definition: atlbase.h:39
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
classinfo
Definition: clsfactory.c:43
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
HRESULT WINAPI FileSystem_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
Definition: filesystem.c:3998
#define CLASS_E_CLASSNOTAVAILABLE
Definition: winerror.h:2663
HRESULT WINAPI Dictionary_CreateInstance(IClassFactory *factory, IUnknown *outer, REFIID riid, void **obj)
Definition: dictionary.c:892
static const IProvideClassInfoVtbl provideclassinfovtbl
Definition: scrrun.c:225
const GUID * guid
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
Definition: scrrun.c:281
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
const GUID IID_IProvideClassInfo
static REFIID tid_ids[]
Definition: scrrun.c:108
#define FIXME(fmt,...)
Definition: debug.h:111
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
r reserved
Definition: btrfs.c:2940
static ITypeLib * typelib
Definition: scrrun.c:105
#define S_FALSE
Definition: winerror.h:2357
static ULONG WINAPI provideclassinfo_AddRef(IProvideClassInfo *iface)
Definition: scrrun.c:204
static ULONG WINAPI provideclassinfo_Release(IProvideClassInfo *iface)
Definition: scrrun.c:210
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define DLL_PROCESS_DETACH
Definition: compat.h:130
static HINSTANCE scrrun_instance
Definition: scrrun.c:36
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT hres
Definition: protocol.c:465
static IClassFactory DictionaryFactory
Definition: scrrun.c:103
LONG HRESULT
Definition: typedefs.h:79
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:6
#define LOCALE_SYSTEM_DEFAULT
static const struct IClassFactoryVtbl scrruncf_vtbl
Definition: scrrun.c:84
unsigned long DWORD
Definition: ntddk_ex.h:95
void init_classinfo(const GUID *guid, IUnknown *outer, struct provideclassinfo *classinfo)
Definition: scrrun.c:232
HRESULT WINAPI DllCanUnloadNow(void)
Definition: scrrun.c:299
static HRESULT WINAPI scrruncf_LockServer(IClassFactory *iface, BOOL fLock)
Definition: scrrun.c:78
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
HRESULT WINAPI DllUnregisterServer(void)
Definition: scrrun.c:271
#define IID_NULL
Definition: guiddef.h:98
HRESULT(* fnCreateInstance)(LPVOID *ppObj)
Definition: scrrun.c:43
HRESULT __wine_unregister_resources(HMODULE module) DECLSPEC_HIDDEN
Definition: register.c:110
WINE_DEFAULT_DEBUG_CHANNEL(scrrun)
static HRESULT WINAPI scrruncf_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppv)
Definition: scrrun.c:45
static HRESULT WINAPI provideclassinfo_QueryInterface(IProvideClassInfo *iface, REFIID riid, void **obj)
Definition: scrrun.c:189
#define ERR(fmt,...)
Definition: debug.h:110
static struct provideclassinfo * impl_from_IProvideClassInfo(IProvideClassInfo *iface)
Definition: scrrun.c:38
#define S_OK
Definition: intsafe.h:51
HRESULT WINAPI LoadRegTypeLib(REFGUID rguid, WORD wVerMajor, WORD wVerMinor, LCID lcid, ITypeLib **ppTLib)
Definition: typelib.c:531
IProvideClassInfo IProvideClassInfo_iface
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static IClassFactory FileSystemFactory
Definition: scrrun.c:102
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
Definition: scrrun.c:239
#define ARRAY_SIZE(a)
Definition: main.h:24
static ULONG WINAPI scrruncf_Release(IClassFactory *iface)
Definition: scrrun.c:72
HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
Definition: scrrun.c:150
#define NULL
Definition: types.h:112
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
static HRESULT load_typelib(void)
Definition: scrrun.c:121
unsigned int ULONG
Definition: retypes.h:1
static HINSTANCE hinst
Definition: edit.c:551
IUnknown * outer
const GUID IID_IClassFactory
static TfClientId tid
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
HRESULT WINAPI DllRegisterServer(void)
Definition: scrrun.c:262
static const struct IClassFactoryVtbl dictcf_vtbl
Definition: scrrun.c:93
static void release_typelib(void)
Definition: scrrun.c:175