(DINPUT): DllCanUnloadNow

Christian Gmeiner christian.gmeiner at students.fh-vorarlberg.ac.at
Sun Dec 11 19:08:20 CST 2005


Fixed DllCanUnloadNow for dinput... hope its okey..

-- 
Christian Gmeiner - student of computer science

http://dxr3plugin.sf.net
http://itb04.ath.cx

-------------- next part --------------
Index: dlls/dinput/dinput_main.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/dinput_main.c,v
retrieving revision 1.60
diff -u -b -r1.60 dinput_main.c
--- dlls/dinput/dinput_main.c   23 Nov 2005 19:29:19 -0000      1.60
+++ dlls/dinput/dinput_main.c   11 Dec 2005 23:36:25 -0000
@@ -3,6 +3,7 @@
  * Copyright 1998 Marcus Meissner
  * Copyright 1998,1999 Lionel Ulmer
  * Copyright 2000-2002 TransGaming Technologies Inc.
+ * Copyright 2005 Christian Gmeiner
  *
  *
  * This library is free software; you can redistribute it and/or
@@ -46,6 +47,8 @@

 WINE_DEFAULT_DEBUG_CHANNEL(dinput);

+LONG DINPUT_refCount = 0;
+
 static const IDirectInput7AVtbl ddi7avt;
 static const IDirectInput7WVtbl ddi7wvt;
 static const IDirectInput8AVtbl ddi8avt;
@@ -93,7 +96,6 @@
            IsEqualGUID(&IID_IDirectInput7A,riid)) {
          This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
          This->lpVtbl = &ddi7avt;
-         This->ref = 1;
          This->dwVersion = dwVersion;
          *ppDI = This;

@@ -105,7 +107,6 @@
            IsEqualGUID(&IID_IDirectInput7W,riid)) {
          This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
          This->lpVtbl = &ddi7wvt;
-         This->ref = 1;
          This->dwVersion = dwVersion;
          *ppDI = This;

@@ -115,7 +116,6 @@
        if (IsEqualGUID(&IID_IDirectInput8A,riid)) {
          This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
          This->lpVtbl = &ddi8avt;
-         This->ref = 1;
          This->dwVersion = dwVersion;
          *ppDI = This;

@@ -125,7 +125,6 @@
        if (IsEqualGUID(&IID_IDirectInput8W,riid)) {
          This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
          This->lpVtbl = &ddi8wvt;
-         This->ref = 1;
          This->dwVersion = dwVersion;
          *ppDI = This;

@@ -144,7 +143,7 @@
        TRACE("(%p,%04lx,%p,%p)\n", hinst,dwVersion,ppDI,punkOuter);
        This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
        This->lpVtbl = &ddi7avt;
-       This->ref = 1;
+
        This->dwVersion = dwVersion;
        *ppDI = (IDirectInputA*)This;
        return 0;
@@ -160,7 +159,7 @@
        TRACE("(%p,%04lx,%p,%p)\n", hinst,dwVersion,ppDI,punkOuter);
        This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
        This->lpVtbl = &ddi7wvt;
-       This->ref = 1;
+
        This->dwVersion = dwVersion;
        *ppDI = (IDirectInputW*)This;
        return 0;
@@ -265,15 +264,16 @@

 static ULONG WINAPI IDirectInputAImpl_AddRef(LPDIRECTINPUT7A iface)
 {
-       IDirectInputImpl *This = (IDirectInputImpl *)iface;
-       return InterlockedIncrement((&This->ref));
+    DINPUT_LockModule();
+    return DINPUT_refCount;
 }

 static ULONG WINAPI IDirectInputAImpl_Release(LPDIRECTINPUT7A iface)
 {
        IDirectInputImpl *This = (IDirectInputImpl *)iface;
        ULONG ref;
-       ref = InterlockedDecrement(&(This->ref));
+    DINPUT_UnlockModule();
+       ref = DINPUT_refCount;
        if (ref == 0)
                HeapFree(GetProcessHeap(),0,This);
        return ref;
@@ -628,14 +628,13 @@
 }

 static ULONG WINAPI DICF_AddRef(LPCLASSFACTORY iface) {
-       IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-       return InterlockedIncrement(&(This->ref));
+    DINPUT_LockModule();
+    return DINPUT_refCount;
 }

 static ULONG WINAPI DICF_Release(LPCLASSFACTORY iface) {
-       IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-       /* static class, won't be  freed */
-       return InterlockedDecrement(&(This->ref));
+    DINPUT_UnlockModule();
+    return DINPUT_refCount;
 }

 static HRESULT WINAPI DICF_CreateInstance(
@@ -680,9 +679,7 @@
  */
 HRESULT WINAPI DllCanUnloadNow(void)
 {
-    FIXME("(void): stub\n");
-
-    return S_FALSE;
+    return DINPUT_refCount == 0 ? S_OK : S_FALSE;
 }

 /***********************************************************************
Index: dlls/dinput/dinput_private.h
===================================================================
RCS file: /home/wine/wine/dlls/dinput/dinput_private.h,v
retrieving revision 1.18
diff -u -b -r1.18 dinput_private.h
--- dlls/dinput/dinput_private.h        3 Aug 2005 11:03:05 -0000       1.18
+++ dlls/dinput/dinput_private.h        11 Dec 2005 23:36:25 -0000
@@ -1,5 +1,6 @@
 /*
  * Copyright 2000 Lionel Ulmer
+ * Copyright 2005 Christian Gmeiner
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,12 +26,18 @@
 #include "winbase.h"
 #include "dinput.h"

+/**********************************************************************
+ * Dll lifetime tracking declaration for dinput.dll
+ */
+extern LONG DINPUT_refCount;
+static inline void DINPUT_LockModule(void) { InterlockedIncrement(&DINPUT_refCount); }
+static inline void DINPUT_UnlockModule(void) { InterlockedDecrement(&DINPUT_refCount); }
+
 /* Implementation specification */
 typedef struct IDirectInputImpl IDirectInputImpl;
 struct IDirectInputImpl
 {
    const void *lpVtbl;
-   LONG  ref;

    /* Used to have an unique sequence number for all the events */
    DWORD evsequence;



More information about the wine-patches mailing list