windowscodecs: Implement DllCanUnloadNow

André Hentschel nerv at dawncrow.de
Sat Mar 10 11:24:39 CST 2012


Needed for dotNet 4.5 preview
---
 dlls/windowscodecs/clsfactory.c        |   15 +++++++++++++--
 dlls/windowscodecs/main.c              |    9 +++++++++
 dlls/windowscodecs/wincodecs_private.h |   12 ++++++++++++
 dlls/windowscodecs/windowscodecs.spec  |    1 +
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/dlls/windowscodecs/clsfactory.c b/dlls/windowscodecs/clsfactory.c
index 0f30115..bd22ce5 100644
--- a/dlls/windowscodecs/clsfactory.c
+++ b/dlls/windowscodecs/clsfactory.c
@@ -112,7 +112,10 @@ static ULONG WINAPI ClassFactoryImpl_Release(IClassFactory *iface)
     TRACE("(%p) refcount=%u\n", iface, ref);
 
     if (ref == 0)
+    {
         HeapFree(GetProcessHeap(), 0, This);
+        unlock_module();
+    }
 
     return ref;
 }
@@ -127,8 +130,14 @@ static HRESULT WINAPI ClassFactoryImpl_CreateInstance(IClassFactory *iface,
 
 static HRESULT WINAPI ClassFactoryImpl_LockServer(IClassFactory *iface, BOOL lock)
 {
-    TRACE("(%p, %i): stub\n", iface, lock);
-    return E_NOTIMPL;
+    TRACE("(%p,%x)\n", iface, lock);
+
+    if(lock)
+        lock_module();
+    else
+        unlock_module();
+
+    return S_OK;
 }
 
 static const IClassFactoryVtbl ClassFactoryImpl_Vtbl = {
@@ -146,6 +155,8 @@ static HRESULT ClassFactoryImpl_Constructor(classinfo *info, REFIID riid, LPVOID
 
     *ppv = NULL;
 
+    lock_module();
+
     This = HeapAlloc(GetProcessHeap(), 0, sizeof(ClassFactoryImpl));
     if (!This) return E_OUTOFMEMORY;
 
diff --git a/dlls/windowscodecs/main.c b/dlls/windowscodecs/main.c
index a6588fd..69e50f5 100644
--- a/dlls/windowscodecs/main.c
+++ b/dlls/windowscodecs/main.c
@@ -32,6 +32,8 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
 
+LONG module_ref = 0;
+
 extern BOOL WINAPI WIC_DllMain(HINSTANCE, DWORD, LPVOID) DECLSPEC_HIDDEN;
 
 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
@@ -49,6 +51,13 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
     return WIC_DllMain(hinstDLL, fdwReason, lpvReserved);
 }
 
+HRESULT WINAPI DllCanUnloadNow(void)
+{
+    TRACE("() ref=%d\n", module_ref);
+
+    return module_ref ? S_FALSE : S_OK;
+}
+
 HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
     UINT srcwidth, UINT srcheight, INT srcstride,
     const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer)
diff --git a/dlls/windowscodecs/wincodecs_private.h b/dlls/windowscodecs/wincodecs_private.h
index 691b1ec..8845e22 100644
--- a/dlls/windowscodecs/wincodecs_private.h
+++ b/dlls/windowscodecs/wincodecs_private.h
@@ -87,4 +87,16 @@ extern HRESULT MetadataReader_Create(const MetadataHandlerVtbl *vtable, IUnknown
 
 extern HRESULT UnknownMetadataReader_CreateInstance(IUnknown *pUnkOuter, REFIID iid, void** ppv) DECLSPEC_HIDDEN;
 
+extern LONG module_ref DECLSPEC_HIDDEN;
+
+static inline void lock_module(void)
+{
+    InterlockedIncrement(&module_ref);
+}
+
+static inline void unlock_module(void)
+{
+    InterlockedDecrement(&module_ref);
+}
+
 #endif /* WINCODECS_PRIVATE_H */
diff --git a/dlls/windowscodecs/windowscodecs.spec b/dlls/windowscodecs/windowscodecs.spec
index d0b6a7e..71022cb 100644
--- a/dlls/windowscodecs/windowscodecs.spec
+++ b/dlls/windowscodecs/windowscodecs.spec
@@ -1,3 +1,4 @@
+@ stdcall -private DllCanUnloadNow()
 @ stdcall -private DllGetClassObject(ptr ptr ptr)
 @ stdcall -private DllRegisterServer()
 @ stdcall -private DllUnregisterServer()
-- 

Best Regards, André Hentschel
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Nachrichtenteil als Anhang
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20120310/c11b1932/attachment.ksh>


More information about the wine-patches mailing list