MSI: replace instances of HeapAlloc/MultiByteToWideChar with the internally defined strdupAtoW

Mike McCormack mike at codeweavers.com
Thu Mar 24 06:20:31 CST 2005


ChangeLog:
* replace instances of HeapAlloc/MultiByteToWideChar with the internally 
defined strdupAtoW
-------------- next part --------------
Index: dlls/msi/msi.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/msi.c,v
retrieving revision 1.68
diff -u -p -r1.68 msi.c
--- dlls/msi/msi.c	23 Mar 2005 10:24:53 -0000	1.68
+++ dlls/msi/msi.c	24 Mar 2005 12:10:54 -0000
@@ -203,26 +203,21 @@ UINT WINAPI MsiOpenDatabaseA(LPCSTR szDB
 {
     HRESULT r = ERROR_FUNCTION_FAILED;
     LPWSTR szwDBPath = NULL, szwPersist = NULL;
-    UINT len;
 
     TRACE("%s %s %p\n", debugstr_a(szDBPath), debugstr_a(szPersist), phDB);
 
     if( szDBPath )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szDBPath, -1, NULL, 0 );
-        szwDBPath = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwDBPath = strdupAtoW( szDBPath );
         if( !szwDBPath )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szDBPath, -1, szwDBPath, len );
     }
 
     if( HIWORD(szPersist) )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szPersist, -1, NULL, 0 );
-        szwPersist = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwPersist = strdupAtoW( szPersist );
         if( !szwPersist )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szPersist, -1, szwPersist, len );
     }
     else
         szwPersist = (LPWSTR) szPersist;
@@ -238,17 +233,16 @@ end:
 
 UINT WINAPI MsiOpenProductA(LPCSTR szProduct, MSIHANDLE *phProduct)
 {
-    UINT len, ret;
+    UINT ret;
     LPWSTR szwProd = NULL;
 
     TRACE("%s %p\n",debugstr_a(szProduct), phProduct);
 
     if( szProduct )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szProduct, -1, NULL, 0 );
-        szwProd = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
-        if( szwProd )
-            MultiByteToWideChar( CP_ACP, 0, szProduct, -1, szwProd, len );
+        szwProd = strdupAtoW( szProduct );
+        if( !szwProd )
+            return ERROR_OUTOFMEMORY;
     }
 
     ret = MsiOpenProductW( szwProd, phProduct );
@@ -353,20 +347,16 @@ UINT WINAPI MsiInstallProductA(LPCSTR sz
 
     if( szPackagePath )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szPackagePath, -1, NULL, 0 );
-        szwPath = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwPath = strdupAtoW( szPackagePath );
         if( !szwPath )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szPackagePath, -1, szwPath, len );
     }
 
     if( szCommandLine )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szCommandLine, -1, NULL, 0 );
-        szwCommand = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwCommand = strdupAtoW( szCommandLine );
         if( !szwCommand )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szCommandLine, -1, szwCommand, len );
     }
  
     r = MsiInstallProductW( szwPath, szwCommand );
@@ -490,10 +480,10 @@ UINT WINAPI MsiConfigureProductExW(LPCWS
         goto end;
     }
   
-    sz = strlenW(szInstalled);
+    sz = lstrlenW(szInstalled);
 
     if (szCommandLine)
-        sz += strlenW(szCommandLine);
+        sz += lstrlenW(szCommandLine);
 
     commandline = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
 
@@ -525,20 +515,16 @@ UINT WINAPI MsiConfigureProductExA(LPCST
 
     if( szProduct )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szProduct, -1, NULL, 0 );
-        szwProduct = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwProduct = strdupAtoW( szProduct );
         if( !szwProduct )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szProduct, -1, szwProduct, len );
     }
 
     if( szCommandLine)
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szCommandLine, -1, NULL, 0 );
-        szwCommandLine= HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwCommandLine = strdupAtoW( szCommandLine );
         if( !szwCommandLine)
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szCommandLine, -1, szwCommandLine, len );
     }
 
     hr = MsiConfigureProductExW( szwProduct, iInstallLevel, eInstallState,
@@ -560,11 +546,9 @@ UINT WINAPI MsiConfigureProductA(LPCSTR 
 
     if( szProduct )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szProduct, -1, NULL, 0 );
-        szwProduct = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwProduct = strdupAtoW( szProduct );
         if( !szwProduct )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szProduct, -1, szwProduct, len );
     }
 
     hr = MsiConfigureProductW( szwProduct, iInstallLevel, eInstallState );
@@ -594,11 +578,9 @@ UINT WINAPI MsiGetProductCodeA(LPCSTR sz
 
     if( szComponent )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szComponent, -1, NULL, 0 );
-        szwComponent = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwComponent = strdupAtoW( szComponent );
         if( !szwComponent )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szComponent, -1, szwComponent, len );
     }
     else
         return ERROR_INVALID_PARAMETER;
@@ -635,22 +617,18 @@ UINT WINAPI MsiGetProductInfoA(LPCSTR sz
         return ERROR_INVALID_PARAMETER;
     if( szProduct )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szProduct, -1, NULL, 0 );
-        szwProduct = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwProduct = strdupAtoW( szProduct );
         if( !szwProduct )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szProduct, -1, szwProduct, len );
     }
     else
         return ERROR_INVALID_PARAMETER;
     
     if( szAttribute )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szAttribute, -1, NULL, 0 );
-        szwAttribute = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwAttribute = strdupAtoW( szAttribute );
         if( !szwAttribute )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szAttribute, -1, szwAttribute, len );
     }
     else
     {
@@ -722,11 +700,9 @@ UINT WINAPI MsiEnableLogA(DWORD dwLogMod
 
     if( szLogFile )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szLogFile, -1, NULL, 0 );
-        szwLogFile = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+        szwLogFile = strdupAtoW( szLogFile );
         if( !szwLogFile )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szLogFile, -1, szwLogFile, len );
     }
     else
         return ERROR_INVALID_PARAMETER;
@@ -760,23 +736,25 @@ UINT WINAPI MsiEnableLogW(DWORD dwLogMod
 
 INSTALLSTATE WINAPI MsiQueryProductStateA(LPCSTR szProduct)
 {
-    LPWSTR szwProduct;
-    UINT len;
-    INSTALLSTATE rc;
+    LPWSTR szwProduct = NULL;
+    INSTALLSTATE r;
 
-    len = MultiByteToWideChar(CP_ACP,0,szProduct,-1,NULL,0);
-    szwProduct = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP,0,szProduct,-1,szwProduct,len);
-    rc = MsiQueryProductStateW(szwProduct);
-    HeapFree(GetProcessHeap(),0,szwProduct);
-    return rc;
+    if( szProduct )
+    {
+         szwProduct = strdupAtoW( szProduct );
+         if( !szwProduct )
+             return ERROR_OUTOFMEMORY;
+    }
+    r = MsiQueryProductStateW( szwProduct );
+    HeapFree( GetProcessHeap(), 0, szwProduct );
+    return r;
 }
 
 INSTALLSTATE WINAPI MsiQueryProductStateW(LPCWSTR szProduct)
 {
     UINT rc;
     INSTALLSTATE rrc = INSTALLSTATE_UNKNOWN;
-    HKEY hkey=0;
+    HKEY hkey = 0;
     static const WCHAR szWindowsInstaller[] = {
          'W','i','n','d','o','w','s','I','n','s','t','a','l','l','e','r',0 };
     DWORD sz;
@@ -1043,18 +1021,16 @@ UINT WINAPI MsiGetProductPropertyW( MSIH
 
 UINT WINAPI MsiVerifyPackageA( LPCSTR szPackage )
 {
-    UINT r, len;
+    UINT r;
     LPWSTR szPack = NULL;
 
     TRACE("%s\n", debugstr_a(szPackage) );
 
     if( szPackage )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szPackage, -1, NULL, 0 );
-        szPack = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
+        szPack = strdupAtoW( szPackage );
         if( !szPack )
             return ERROR_OUTOFMEMORY;
-        MultiByteToWideChar( CP_ACP, 0, szPackage, -1, szPack, len );
     }
 
     r = MsiVerifyPackageW( szPack );
@@ -1082,27 +1058,23 @@ INSTALLSTATE WINAPI MsiGetComponentPathA
 {
     LPWSTR szwProduct = NULL, szwComponent = NULL, lpwPathBuf= NULL;
     INSTALLSTATE rc;
-    UINT len, incoming_len;
+    UINT incoming_len;
 
     if( szProduct )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szProduct, -1, NULL, 0 );
-        szwProduct= HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
+        szwProduct = strdupAtoW( szProduct );
         if( !szwProduct)
             return ERROR_OUTOFMEMORY;
-        MultiByteToWideChar( CP_ACP, 0, szProduct, -1, szwProduct, len );
     }
 
     if( szComponent )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szComponent, -1, NULL, 0 );
-        szwComponent= HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
+        szwComponent = strdupAtoW( szComponent );
         if( !szwComponent )
         {
             HeapFree( GetProcessHeap(), 0, szwProduct);
             return ERROR_OUTOFMEMORY;
         }
-        MultiByteToWideChar( CP_ACP, 0, szComponent, -1, szwComponent, len );
     }
 
     if( pcchBuf && *pcchBuf > 0 )
@@ -1205,29 +1177,24 @@ end:
 INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature)
 {
     INSTALLSTATE rc;
-    UINT len;
     LPWSTR szwProduct= NULL;
     LPWSTR szwFeature= NULL;
 
     if( szProduct )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szProduct, -1, NULL, 0 );
-        szwProduct= HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
+        szwProduct = strdupAtoW( szProduct );
         if( !szwProduct)
             return ERROR_OUTOFMEMORY;
-        MultiByteToWideChar( CP_ACP, 0, szProduct, -1, szwProduct, len );
     }
 
     if( szFeature )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szFeature, -1, NULL, 0 );
-        szwFeature= HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
+        szwFeature = strdupAtoW( szFeature );
         if( !szwFeature)
         {
             HeapFree( GetProcessHeap(), 0, szwProduct);
             return ERROR_OUTOFMEMORY;
         }
-        MultiByteToWideChar( CP_ACP, 0, szFeature, -1, szwFeature, len );
     }
 
     rc = MsiQueryFeatureStateW(szwProduct, szwFeature);
@@ -1251,15 +1218,13 @@ UINT WINAPI MsiGetFileVersionA(LPCSTR sz
                 DWORD* pcchVersionBuf, LPSTR lpLangBuf, DWORD* pcchLangBuf)
 {
     LPWSTR szwFilePath = NULL, lpwVersionBuff = NULL, lpwLangBuff = NULL;
-    UINT len, ret = ERROR_OUTOFMEMORY;
+    UINT ret = ERROR_OUTOFMEMORY;
     
     if( szFilePath )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szFilePath, -1, NULL, 0 );
-        szwFilePath = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
+        szwFilePath = strdupAtoW( szFilePath );
         if( !szwFilePath )
             goto end;
-        MultiByteToWideChar( CP_ACP, 0, szFilePath, -1, szwFilePath, len );
     }
     
     if( lpVersionBuf && pcchVersionBuf && *pcchVersionBuf )
Index: dlls/msi/msiquery.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/msiquery.c,v
retrieving revision 1.25
diff -u -p -r1.25 msiquery.c
--- dlls/msi/msiquery.c	10 Mar 2005 11:15:40 -0000	1.25
+++ dlls/msi/msiquery.c	24 Mar 2005 12:10:54 -0000
@@ -86,11 +86,9 @@ UINT WINAPI MsiDatabaseOpenViewA(MSIHAND
 
     if( szQuery )
     {
-        UINT len = MultiByteToWideChar( CP_ACP, 0, szQuery, -1, NULL, 0 );
-        szwQuery = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
+        szwQuery = strdupAtoW( szQuery );
         if( !szwQuery )
             return ERROR_FUNCTION_FAILED;
-        MultiByteToWideChar( CP_ACP, 0, szQuery, -1, szwQuery, len );
     }
     else
         szwQuery = NULL;
@@ -672,16 +670,15 @@ UINT WINAPI MsiDatabaseGetPrimaryKeysA(M
                     LPCSTR table, MSIHANDLE* phRec)
 {
     LPWSTR szwTable = NULL;
-    DWORD len;
     UINT r;
 
     TRACE("%ld %s %p\n", hdb, debugstr_a(table), phRec);
 
     if( table )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, table, -1, NULL, 0 );
-        szwTable = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
-        MultiByteToWideChar( CP_ACP, 0, table, -1, szwTable, len );
+        szwTable = strdupAtoW( table );
+        if( !szwTable )
+            return ERROR_OUTOFMEMORY;
     }
     r = MsiDatabaseGetPrimaryKeysW( hdb, szwTable, phRec );
     HeapFree( GetProcessHeap(), 0, szwTable );
Index: dlls/msi/package.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/package.c,v
retrieving revision 1.37
diff -u -p -r1.37 package.c
--- dlls/msi/package.c	10 Mar 2005 11:15:40 -0000	1.37
+++ dlls/msi/package.c	24 Mar 2005 12:10:55 -0000
@@ -469,14 +469,13 @@ UINT WINAPI MsiOpenPackageW(LPCWSTR szPa
 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
 {
     LPWSTR szwPack = NULL;
-    UINT len, ret;
+    UINT ret;
 
     if( szPackage )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szPackage, -1, NULL, 0 );
-        szwPack = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
-        if( szwPack )
-            MultiByteToWideChar( CP_ACP, 0, szPackage, -1, szwPack, len );
+        szwPack = strdupAtoW( szPackage );
+        if( !szwPack )
+            return ERROR_OUTOFMEMORY;
     }
 
     ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
@@ -638,29 +637,20 @@ UINT WINAPI MsiSetPropertyA( MSIHANDLE h
 {
     LPWSTR szwName = NULL, szwValue = NULL;
     UINT hr = ERROR_INSTALL_FAILURE;
-    UINT len;
 
-    if (0 == hInstall) {
-      return ERROR_INVALID_HANDLE;
-    }
-    if (NULL == szName) {
-      return ERROR_INVALID_PARAMETER;
-    }
-    if (NULL == szValue) {
-      return ERROR_INVALID_PARAMETER;
+    if( szName )
+    {
+        szwName = strdupAtoW( szName );
+        if( !szwName )
+            goto end;
     }
 
-    len = MultiByteToWideChar( CP_ACP, 0, szName, -1, NULL, 0 );
-    szwName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
-    if( !szwName )
-        goto end;
-    MultiByteToWideChar( CP_ACP, 0, szName, -1, szwName, len );
-
-    len = MultiByteToWideChar( CP_ACP, 0, szValue, -1, NULL, 0 );
-    szwValue = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
-    if( !szwValue)
-        goto end;
-    MultiByteToWideChar( CP_ACP, 0, szValue , -1, szwValue, len );
+    if( szValue )
+    {
+        szwValue = strdupAtoW( szValue );
+        if( !szwValue)
+            goto end;
+    }
 
     hr = MsiSetPropertyW( hInstall, szwName, szwValue);
 
@@ -703,7 +693,7 @@ UINT MSI_SetPropertyW( MSIPACKAGE *packa
     }
     else
     {
-       strcpyW(Query,Insert);
+        strcpyW(Query,Insert);
 
         row = MSI_CreateRecord(2);
         MSI_RecordSetStringW(row,1,szName);
@@ -732,8 +722,13 @@ UINT WINAPI MsiSetPropertyW( MSIHANDLE h
     MSIPACKAGE *package;
     UINT ret;
 
+    if (NULL == szName)
+        return ERROR_INVALID_PARAMETER;
+    if (NULL == szValue)
+        return ERROR_INVALID_PARAMETER;
+
     package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
-    if( !package)
+    if( !package )
         return ERROR_INVALID_HANDLE;
     ret = MSI_SetPropertyW( package, szName, szValue);
     msiobj_release( &package->hdr );
@@ -808,17 +803,18 @@ UINT MSI_GetPropertyA(MSIPACKAGE *packag
                            LPSTR szValueBuf, DWORD* pchValueBuf)
 {
     MSIRECORD *row;
-    UINT rc, len;
-    LPWSTR szwName;
+    UINT rc;
+    LPWSTR szwName = NULL;
 
     if (*pchValueBuf > 0)
         szValueBuf[0] = 0;
     
-    len = MultiByteToWideChar( CP_ACP, 0, szName, -1, NULL, 0 );
-    szwName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
-    if (!szwName)
-        return ERROR_NOT_ENOUGH_MEMORY;
-    MultiByteToWideChar( CP_ACP, 0, szName, -1, szwName, len );
+    if( szName )
+    {
+        szwName = strdupAtoW( szName );
+        if (!szwName)
+            return ERROR_NOT_ENOUGH_MEMORY;
+    }
 
     rc = MSI_GetPropertyRow(package, szwName, &row);
     if (rc == ERROR_SUCCESS)
Index: dlls/msi/preview.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/preview.c,v
retrieving revision 1.4
diff -u -p -r1.4 preview.c
--- dlls/msi/preview.c	10 Mar 2005 11:15:40 -0000	1.4
+++ dlls/msi/preview.c	24 Mar 2005 12:10:56 -0000
@@ -132,16 +132,16 @@ UINT WINAPI MsiPreviewDialogW( MSIHANDLE
 
 UINT WINAPI MsiPreviewDialogA( MSIHANDLE hPreview, LPCSTR szDialogName )
 {
-    UINT r, len;
+    UINT r;
     LPWSTR strW = NULL;
 
     TRACE("%ld %s\n", hPreview, debugstr_a(szDialogName));
 
     if( szDialogName )
     {
-        len = MultiByteToWideChar( CP_ACP, 0, szDialogName, -1, NULL, 0 );
-        strW = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
-        MultiByteToWideChar( CP_ACP, 0, szDialogName, -1, strW, len );
+        strW = strdupAtoW( szDialogName );
+        if( !strW )
+            return ERROR_OUTOFMEMORY;
     }
     r = MsiPreviewDialogW( hPreview, strW );
     HeapFree( GetProcessHeap(), 0, strW );


More information about the wine-patches mailing list