Replace instances of HeapAlloc/MultiByteToWideChar with the internally

defined strdupAtoW.
oldstable
Mike McCormack 2005-03-24 19:04:06 +00:00 committed by Alexandre Julliard
parent f8f64406fc
commit 77a19ed8e6
4 changed files with 76 additions and 118 deletions

View File

@ -203,26 +203,21 @@ UINT WINAPI MsiOpenDatabaseA(LPCSTR szDBPath, LPCSTR szPersist, MSIHANDLE *phDB)
{
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 szPackagePath, LPCSTR szCommandLine)
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(LPCWSTR szProduct, int iInstallLevel,
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(LPCSTR szProduct, int iInstallLevel,
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 szProduct, int iInstallLevel,
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 szComponent, LPSTR szBuffer)
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 szProduct, LPCSTR szAttribute,
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 dwLogMode, LPCSTR szLogFile, DWORD attributes)
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 dwLogMode, LPCWSTR szLogFile, DWORD attributes)
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( MSIHANDLE hProduct, LPCWSTR szProperty,
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(LPCSTR szProduct, LPCSTR szComponent,
{
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 szFilePath, LPSTR lpVersionBuf,
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 )

View File

@ -86,11 +86,9 @@ UINT WINAPI MsiDatabaseOpenViewA(MSIHANDLE hdb,
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(MSIHANDLE hdb,
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 );

View File

@ -469,14 +469,13 @@ UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
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 hInstall, LPCSTR szName, LPCSTR szValue)
{
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 *package, LPCWSTR szName, LPCWSTR szValue)
}
else
{
strcpyW(Query,Insert);
strcpyW(Query,Insert);
row = MSI_CreateRecord(2);
MSI_RecordSetStringW(row,1,szName);
@ -732,8 +722,13 @@ UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue
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 *package, LPCSTR szName,
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)

View File

@ -132,16 +132,16 @@ UINT WINAPI MsiPreviewDialogW( MSIHANDLE hPreview, LPCWSTR szDialogName )
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 );