Jacek Caban : jscript: Added DllCanUnloadNow implementation.

Alexandre Julliard julliard at winehq.org
Tue Mar 25 06:58:04 CDT 2008


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Mar 24 21:53:34 2008 +0100

jscript: Added DllCanUnloadNow implementation.

---

 dlls/jscript/jscript.c      |    6 +++++-
 dlls/jscript/jscript.h      |   12 ++++++++++++
 dlls/jscript/jscript_main.c |   13 +++++++++++--
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index 79b55c8..7d7385a 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -97,8 +97,10 @@ static ULONG WINAPI JScript_Release(IActiveScript *iface)
 
     TRACE("(%p) ref=%d\n", iface, ref);
 
-    if(!ref)
+    if(!ref) {
         heap_free(This);
+        unlock_module();
+    }
 
     return ref;
 }
@@ -427,6 +429,8 @@ HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pUn
 
     TRACE("(%p %s %p)\n", pUnkOuter, debugstr_guid(riid), ppv);
 
+    lock_module();
+
     ret = heap_alloc(sizeof(*ret));
 
     ret->lpIActiveScriptVtbl                 = &JScriptVtbl;
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 6a7ec76..afdd0c7 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -28,6 +28,18 @@
 
 HRESULT WINAPI JScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
 
+extern LONG module_ref;
+
+static inline void lock_module(void)
+{
+    InterlockedIncrement(&module_ref);
+}
+
+static inline void unlock_module(void)
+{
+    InterlockedDecrement(&module_ref);
+}
+
 static inline void *heap_alloc(size_t len)
 {
     return HeapAlloc(GetProcessHeap(), 0, len);
diff --git a/dlls/jscript/jscript_main.c b/dlls/jscript/jscript_main.c
index f4c4bf1..92999fb 100644
--- a/dlls/jscript/jscript_main.c
+++ b/dlls/jscript/jscript_main.c
@@ -30,6 +30,8 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
 
+LONG module_ref = 0;
+
 static const CLSID CLSID_JScript =
     {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
 static const CLSID CLSID_JScriptAuthor =
@@ -75,6 +77,12 @@ static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
 {
     TRACE("(%p)->(%x)\n", iface, fLock);
+
+    if(fLock)
+        lock_module();
+    else
+        unlock_module();
+
     return S_OK;
 }
 
@@ -127,8 +135,9 @@ HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
  */
 HRESULT WINAPI DllCanUnloadNow(void)
 {
-    FIXME("()\n");
-    return S_FALSE;
+    TRACE("() ref=%d\n", module_ref);
+
+    return module_ref ? S_FALSE : S_OK;
 }
 
 /***********************************************************************




More information about the wine-cvs mailing list