MSHTML: DllCanUnloadNow implementation

Jacek Caban jack at itma.pwr.wroc.pl
Mon Aug 1 10:26:52 CDT 2005


Changelog:
    Added DllCanUnloadNow implementation
-------------- next part --------------
Index: dlls/mshtml/htmldoc.c
===================================================================
RCS file: /home/wine/wine/dlls/mshtml/htmldoc.c,v
retrieving revision 1.13
diff -u -p -r1.13 htmldoc.c
--- dlls/mshtml/htmldoc.c	1 Aug 2005 10:59:45 -0000	1.13
+++ dlls/mshtml/htmldoc.c	1 Aug 2005 15:18:22 -0000
@@ -140,6 +140,8 @@ static ULONG WINAPI HTMLDocument_Release
         if(This->nscontainer)
             HTMLDocument_NSContainer_Destroy(This);
         HeapFree(GetProcessHeap(), 0, This);
+
+        UNLOCK_MODULE();
     }
 
     return ref;
@@ -974,8 +976,12 @@ HRESULT HTMLDocument_Create(IUnknown *pU
     ret->ref = 0;
 
     hres = IHTMLDocument_QueryInterface(HTMLDOC(ret), riid, ppvObject);
-    if(FAILED(hres))
+    if(FAILED(hres)) {
         HeapFree(GetProcessHeap(), 0, ret);
+        return hres;
+    }
+
+    LOCK_MODULE();
 
     HTMLDocument_Persist_Init(ret);
     HTMLDocument_OleObj_Init(ret);
Index: dlls/mshtml/main.c
===================================================================
RCS file: /home/wine/wine/dlls/mshtml/main.c,v
retrieving revision 1.17
diff -u -p -r1.17 main.c
--- dlls/mshtml/main.c	1 Aug 2005 10:59:45 -0000	1.17
+++ dlls/mshtml/main.c	1 Aug 2005 15:18:23 -0000
@@ -48,6 +48,7 @@
 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
 
 HINSTANCE hInst;
+LONG module_ref = 0;
 
 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
 {
@@ -100,8 +101,10 @@ static ULONG WINAPI ClassFactory_Release
 
     TRACE("(%p) ref = %lu\n", This, ref);
 
-    if(!ref)
+    if(!ref) {
         HeapFree(GetProcessHeap(), 0, This);
+        UNLOCK_MODULE();
+    }
 
     return ref;
 }
@@ -115,7 +118,13 @@ static HRESULT WINAPI ClassFactory_Creat
 
 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
 {
-    FIXME("(%p)->(%x) stub\n", iface, dolock);
+    TRACE("(%p)->(%x)\n", iface, dolock);
+
+    if(dolock)
+        LOCK_MODULE();
+    else
+        UNLOCK_MODULE();
+
     return S_OK;
 }
 
@@ -137,7 +146,9 @@ static HRESULT ClassFactory_Create(REFII
     ret->fnCreateInstance = fnCreateInstance;
 
     hres = IClassFactory_QueryInterface((IClassFactory*)ret, riid, ppv);
-    if(FAILED(hres)) {
+    if(SUCCEEDED(hres)) {
+        LOCK_MODULE();
+    }else {
         HeapFree(GetProcessHeap(), 0, ret);
         *ppv = NULL;
     }
@@ -172,8 +183,8 @@ HRESULT WINAPI MSHTML_DllGetClassObject(
 
 HRESULT WINAPI MSHTML_DllCanUnloadNow(void)
 {
-    FIXME("()\n");
-    return S_FALSE;
+    TRACE("() ref=%ld\n", module_ref);
+    return module_ref ? S_FALSE : S_OK;
 }
 
 /***********************************************************************
Index: dlls/mshtml/mshtml_private.h
===================================================================
RCS file: /home/wine/wine/dlls/mshtml/mshtml_private.h,v
retrieving revision 1.17
diff -u -p -r1.17 mshtml_private.h
--- dlls/mshtml/mshtml_private.h	1 Aug 2005 10:59:45 -0000	1.17
+++ dlls/mshtml/mshtml_private.h	1 Aug 2005 15:18:23 -0000
@@ -108,4 +108,8 @@ DEFINE_GUID(CLSID_MailtoProtocol, 0x3050
 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
 DEFINE_GUID(CLSID_SysimageProtocol, 0x76E67A63, 0x06E9, 0x11D2, 0xA8,0x40, 0x00,0x60,0x08,0x05,0x93,0x82);
 
+extern LONG module_ref;
+#define LOCK_MODULE()   InterlockedIncrement(&module_ref)
+#define UNLOCK_MODULE() InterlockedDecrement(&module_ref)
+
 extern HINSTANCE hInst;
Index: dlls/mshtml/protocol.c
===================================================================
RCS file: /home/wine/wine/dlls/mshtml/protocol.c,v
retrieving revision 1.5
diff -u -p -r1.5 protocol.c
--- dlls/mshtml/protocol.c	12 Jul 2005 17:00:58 -0000	1.5
+++ dlls/mshtml/protocol.c	1 Aug 2005 15:18:23 -0000
@@ -51,8 +51,7 @@ typedef struct {
     const IClassFactoryVtbl         *lpClassFactoryVtbl;
 } ProtocolFactory;
 
-#define PROTOCOLINFO_THIS(iface) \
-    (ProtocolFactory*)((char*)(iface)-offsetof(ProtocolFactory,lpInternetProtocolInfoVtbl))
+#define PROTOCOLINFO_THIS(iface) DEFINE_THIS(ProtocolFactory, InternetProtocolInfo, iface)
 
 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface, REFIID riid, void **ppv)
 {
@@ -83,6 +82,7 @@ static ULONG WINAPI InternetProtocolInfo
 {
     ProtocolFactory *This = PROTOCOLINFO_THIS(iface);
     TRACE("(%p)\n", This);
+    LOCK_MODULE();
     return 2;
 }
 
@@ -90,13 +90,13 @@ static ULONG WINAPI InternetProtocolInfo
 {
     ProtocolFactory *This = PROTOCOLINFO_THIS(iface);
     TRACE("(%p)\n", This);
+    UNLOCK_MODULE();
     return 1;
 }
 
 #undef PROTOCOLINFO_THIS
 
-#define CLASSFACTORY_THIS(iface) \
-    (ProtocolFactory*)((char*)(iface)-offsetof(ProtocolFactory,lpClassFactoryVtbl))
+#define CLASSFACTORY_THIS(iface) DEFINE_THIS(ProtocolFactory, ClassFactory, iface)
 
 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
 {
@@ -119,7 +119,14 @@ static ULONG WINAPI ClassFactory_Release
 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
 {
     ProtocolFactory *This = CLASSFACTORY_THIS(iface);
-    FIXME("(%p)->(%x)\n", This, dolock);
+
+    TRACE("(%p)->(%x)\n", This, dolock);
+
+    if(dolock)
+        LOCK_MODULE();
+    else
+        UNLOCK_MODULE();
+
     return S_OK;
 }
 
@@ -176,8 +183,10 @@ static ULONG WINAPI AboutProtocol_Releas
 
     TRACE("(%p) ref=%lx\n", iface, ref);
 
-    if(!ref)
+    if(!ref) {
         HeapFree(GetProcessHeap(), 0, This);
+        UNLOCK_MODULE();
+    }
 
     return ref;
 }
@@ -287,7 +296,9 @@ static HRESULT WINAPI AboutProtocolFacto
 
     hres = IUnknown_QueryInterface((IUnknown*)ret, riid, ppv);
 
-    if(FAILED(hres))
+    if(SUCCEEDED(hres))
+        LOCK_MODULE();
+    else
         HeapFree(GetProcessHeap(), 0, ret);
 
     return hres;
@@ -408,6 +419,7 @@ static ULONG WINAPI ResProtocol_Release(
     if(!ref) {
         HeapFree(GetProcessHeap(), 0, This->data);
         HeapFree(GetProcessHeap(), 0, This);
+        UNLOCK_MODULE();
     }
 
     return ref;
@@ -612,7 +624,9 @@ static HRESULT WINAPI ResProtocolFactory
 
     hres = IUnknown_QueryInterface((IUnknown*)ret, riid, ppv);
 
-    if(FAILED(hres))
+    if(SUCCEEDED(hres))
+        LOCK_MODULE();
+    else
         HeapFree(GetProcessHeap(), 0, ret);
 
     return hres;
@@ -688,6 +702,6 @@ HRESULT ProtocolFactory_Create(REFCLSID 
         FIXME("not implemented protocol %s\n", debugstr_guid(rclsid));
         return CLASS_E_CLASSNOTAVAILABLE;
     }
-
+ 
     return IUnknown_QueryInterface((IUnknown*)cf, riid, ppv);
 }


More information about the wine-patches mailing list