Alistair Leslie-Hughes : scrrun: Add typelib support.

Alexandre Julliard julliard at winehq.org
Thu Jul 12 18:00:34 CDT 2012


Module: wine
Branch: master
Commit: 6c5588f95d2e27aa14a1cc15d4fdfda012a4bd2f
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6c5588f95d2e27aa14a1cc15d4fdfda012a4bd2f

Author: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date:   Fri Jun 15 15:17:42 2012 +1000

scrrun: Add typelib support.

---

 dlls/scrrun/Makefile.in      |    2 +-
 dlls/scrrun/filesystem.c     |   39 ++++++++++++++++++------
 dlls/scrrun/scrrun.c         |   68 ++++++++++++++++++++++++++++++++++++++++-
 dlls/scrrun/scrrun_private.h |   32 +++++++++++++++++++
 4 files changed, 128 insertions(+), 13 deletions(-)

diff --git a/dlls/scrrun/Makefile.in b/dlls/scrrun/Makefile.in
index d2ceb87..f6dcf62 100644
--- a/dlls/scrrun/Makefile.in
+++ b/dlls/scrrun/Makefile.in
@@ -1,5 +1,5 @@
 MODULE    = scrrun.dll
-IMPORTS   = uuid
+IMPORTS   = uuid oleaut32
 
 C_SRCS = \
 	filesystem.c \
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c
index a14d926..cd397a4 100644
--- a/dlls/scrrun/filesystem.c
+++ b/dlls/scrrun/filesystem.c
@@ -26,6 +26,7 @@
 #include "ole2.h"
 #include "dispex.h"
 #include "scrrun.h"
+#include "scrrun_private.h"
 
 #include "wine/debug.h"
 
@@ -90,19 +91,26 @@ static HRESULT WINAPI filesys_GetTypeInfoCount(IFileSystem3 *iface, UINT *pctinf
 static HRESULT WINAPI filesys_GetTypeInfo(IFileSystem3 *iface, UINT iTInfo,
                                         LCID lcid, ITypeInfo **ppTInfo)
 {
-    FIXME("(%p)->(%u %u %p)\n", iface, iTInfo, lcid, ppTInfo);
-
-    return E_NOTIMPL;
-}
+    TRACE("(%p)->(%u %u %p)\n", iface, iTInfo, lcid, ppTInfo);
+    return get_typeinfo(IFileSystem3_tid, ppTInfo);}
 
 static HRESULT WINAPI filesys_GetIDsOfNames(IFileSystem3 *iface, REFIID riid,
                                         LPOLESTR *rgszNames, UINT cNames,
                                         LCID lcid, DISPID *rgDispId)
 {
-    FIXME("(%p)->(%s %p %u %u %p)\n", iface, debugstr_guid(riid), rgszNames, cNames,
-          lcid, rgDispId);
+    ITypeInfo *typeinfo;
+    HRESULT hr;
 
-    return E_NOTIMPL;
+    TRACE("(%p)->(%s %p %u %u %p)\n", iface, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
+
+    hr = get_typeinfo(IFileSystem3_tid, &typeinfo);
+    if(SUCCEEDED(hr))
+    {
+        hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
+        ITypeInfo_Release(typeinfo);
+    }
+
+    return hr;
 }
 
 static HRESULT WINAPI filesys_Invoke(IFileSystem3 *iface, DISPID dispIdMember,
@@ -110,10 +118,21 @@ static HRESULT WINAPI filesys_Invoke(IFileSystem3 *iface, DISPID dispIdMember,
                                       DISPPARAMS *pDispParams, VARIANT *pVarResult,
                                       EXCEPINFO *pExcepInfo, UINT *puArgErr)
 {
-    FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", iface, dispIdMember, debugstr_guid(riid),
-          lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
+    ITypeInfo *typeinfo;
+    HRESULT hr;
 
-    return E_NOTIMPL;
+    TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", iface, dispIdMember, debugstr_guid(riid),
+           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
+
+    hr = get_typeinfo(IFileSystem3_tid, &typeinfo);
+    if(SUCCEEDED(hr))
+    {
+        hr = ITypeInfo_Invoke(typeinfo, &iface, dispIdMember, wFlags,
+                pDispParams, pVarResult, pExcepInfo, puArgErr);
+        ITypeInfo_Release(typeinfo);
+    }
+
+    return hr;
 }
 
 static HRESULT WINAPI filesys_get_Drives(IFileSystem3 *iface, IDriveCollection **ppdrives)
diff --git a/dlls/scrrun/scrrun.c b/dlls/scrrun/scrrun.c
index d1e2de2..d5ea369 100644
--- a/dlls/scrrun/scrrun.c
+++ b/dlls/scrrun/scrrun.c
@@ -27,6 +27,7 @@
 
 #include <initguid.h>
 #include "scrrun.h"
+#include "scrrun_private.h"
 
 #include "wine/debug.h"
 
@@ -36,8 +37,6 @@ static HINSTANCE scrrun_instance;
 
 typedef HRESULT (*fnCreateInstance)(LPVOID *ppObj);
 
-extern HRESULT WINAPI FileSystem_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
-
 static HRESULT WINAPI scrruncf_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppv )
 {
     *ppv = NULL;
@@ -88,6 +87,70 @@ static const struct IClassFactoryVtbl scrruncf_vtbl =
 
 static IClassFactory FileSystemFactory = { &scrruncf_vtbl };
 
+static ITypeLib *typelib;
+static ITypeInfo *typeinfos[LAST_tid];
+
+static REFIID tid_ids[] = {
+    &IID_NULL,
+    &IID_IFileSystem3,
+};
+
+static HRESULT load_typelib(void)
+{
+    HRESULT hres;
+    ITypeLib *tl;
+
+    hres = LoadRegTypeLib(&LIBID_Scripting, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
+    if(FAILED(hres)) {
+        ERR("LoadRegTypeLib failed: %08x\n", hres);
+        return hres;
+    }
+
+    if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
+        ITypeLib_Release(tl);
+    return hres;
+}
+
+HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo)
+{
+    HRESULT hres;
+
+    if (!typelib)
+        hres = load_typelib();
+    if (!typelib)
+        return hres;
+
+    if(!typeinfos[tid]) {
+        ITypeInfo *ti;
+
+        hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
+        if(FAILED(hres)) {
+            ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_ids[tid]), hres);
+            return hres;
+        }
+
+        if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), ti, NULL))
+            ITypeInfo_Release(ti);
+    }
+
+    *typeinfo = typeinfos[tid];
+    return S_OK;
+}
+
+static void release_typelib(void)
+{
+    unsigned i;
+
+    if(!typelib)
+        return;
+
+    for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
+        if(typeinfos[i])
+            ITypeInfo_Release(typeinfos[i]);
+
+    ITypeLib_Release(typelib);
+}
+
 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
 {
     TRACE("%p, %u, %p\n", hinst, reason, reserved);
@@ -101,6 +164,7 @@ BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
             scrrun_instance = hinst;
             break;
         case DLL_PROCESS_DETACH:
+            release_typelib();
             break;
     }
     return TRUE;
diff --git a/dlls/scrrun/scrrun_private.h b/dlls/scrrun/scrrun_private.h
new file mode 100644
index 0000000..fc700a6
--- /dev/null
+++ b/dlls/scrrun/scrrun_private.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012 Alistair Leslie-Hughes
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#ifndef _SCRRUN_PRIVATE_H_
+#define _SCRRUN_PRIVATE_H
+
+extern HRESULT WINAPI FileSystem_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
+
+typedef enum tid_t
+{
+    NULL_tid,
+    IFileSystem3_tid,
+    LAST_tid
+} tid_t;
+
+HRESULT get_typeinfo(tid_t tid, ITypeInfo **typeinfo) DECLSPEC_HIDDEN;
+
+#endif




More information about the wine-cvs mailing list