[MSI] DllCanUnloadNow

Christian Gmeiner christian.gmeiner at students.fh-vorarlberg.ac.at
Sat Dec 3 07:20:12 CST 2005


This patch adds a correct DllCanUnloadNow to msi.dll. It also fixes some 
spacing stuff.
As this is my first patch for wine i am very curios if my patch gets 
into cvs :)

Greets,
Christian

-- 
Christian Gmeiner - student of computer science

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

-------------- next part --------------
Index: dlls/msi/msi.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/msi.c,v
retrieving revision 1.117
diff -u -r1.117 msi.c
--- dlls/msi/msi.c      11 Nov 2005 10:52:53 -0000      1.117
+++ dlls/msi/msi.c      2 Dec 2005 16:01:59 -0000
@@ -2,6 +2,7 @@
  * Implementation of the Microsoft Installer (msi.dll)
  *
  * Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
+ * 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
@@ -53,8 +54,24 @@
 WCHAR gszLogFile[MAX_PATH];
 HINSTANCE msi_hInstance;

+LONG dll_count = 0;
+
 static const WCHAR installerW[] = {'\\','I','n','s','t','a','l','l','e','r',0};

+/**********************************************************************
+ * Dll lifetime tracking declaration
+ */
+void LockModule(void)
+{
+    InterlockedIncrement(&dll_count);
+}
+
+void UnlockModule(void)
+{
+    InterlockedDecrement(&dll_count);
+}
+
+
 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
 {
     UINT r;
@@ -457,7 +474,7 @@
         if( !szwProduct )
             goto end;
     }
-
+
     if( szAttribute )
     {
         szwAttribute = strdupAtoW( szAttribute );
@@ -510,7 +527,7 @@
         return ERROR_INVALID_PARAMETER;
     if (NULL == szProduct || NULL == szAttribute)
         return ERROR_INVALID_PARAMETER;
-
+
     /* check for special properties */
     if (strcmpW(szAttribute, INSTALLPROPERTY_PACKAGECODEW)==0)
     {
@@ -1285,11 +1302,17 @@

 static ULONG WINAPI MsiCF_AddRef(LPCLASSFACTORY iface)
 {
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    TRACE("(%p): AddRef\n", This);
+    LockModule();
     return 2;
 }

 static ULONG WINAPI MsiCF_Release(LPCLASSFACTORY iface)
 {
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    TRACE("(%p): ReleaseRef\n", This);
+    UnlockModule();
     return 1;
 }

@@ -1304,9 +1327,13 @@

 static HRESULT WINAPI MsiCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
 {
-    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    TRACE("(%p)->(%d)\n", iface, dolock);
+
+    if(dolock)
+        LockModule();
+    else
+        UnlockModule();

-    FIXME("%p %d\n", This, dolock);
     return S_OK;
 }

@@ -1363,7 +1390,7 @@
  */
 HRESULT WINAPI DllCanUnloadNow(void)
 {
-    return S_FALSE;
+    return dll_count == 0 ? S_OK : S_FALSE;
 }

 /***********************************************************************
@@ -1510,7 +1537,7 @@
     TRACE("%s %s %li %s %li %li %p %p\n", debugstr_w(szComponent),
           debugstr_w(szQualifier), dwInstallMode, debugstr_w(szProduct),
           Unused1, Unused2, lpPathBuf, pcchPathBuf);
-
+
     rc = MSIREG_OpenUserComponentsKey(szComponent, &hkey, FALSE);
     if (rc != ERROR_SUCCESS)
         return ERROR_INDEX_ABSENT;
@@ -1533,12 +1560,12 @@
     }

     MsiDecomposeDescriptorW(info, product, feature, component, &sz);
-
+
     if (!szProduct)
         rc = MsiGetComponentPathW(product, component, lpPathBuf, pcchPathBuf);
     else
         rc = MsiGetComponentPathW(szProduct, component, lpPathBuf, pcchPathBuf);
-
+
     RegCloseKey(hkey);
     msi_free(info);

@@ -1662,7 +1689,7 @@
     }
     if (pcchSerialBuf)
         *pcchSerialBuf = sz / sizeof(WCHAR);
-
+
     RegCloseKey(hkey);
     return USERINFOSTATE_PRESENT;
 }
@@ -1889,7 +1916,7 @@
         { *ptr = 's'; ptr++; }
     if (dwReinstallMode & REINSTALLMODE_PACKAGE)
         { *ptr = 'v'; ptr++; }
-
+
     sz = sizeof(sourcepath);
     MsiSourceListGetInfoW(szProduct, NULL, MSIINSTALLCONTEXT_USERMANAGED,
             MSICODE_PRODUCT, INSTALLPROPERTY_LASTUSEDSOURCEW, sourcepath,
@@ -1910,7 +1937,7 @@
         return r;

     MSI_SetPropertyW(package,REINSTALLMODE,reinstallmode);
-
+
     sz = lstrlenW(szInstalled);
     sz += lstrlenW(fmt);
     sz += lstrlenW(szFeature);
@@ -1943,7 +1970,7 @@
     wszFeature = strdupAtoW(szFeature);

     rc = MsiReinstallFeatureW(wszProduct, wszFeature, dwReinstallMode);
-
+
     msi_free(wszProduct);
     msi_free(wszFeature);
     return rc;



More information about the wine-patches mailing list