implemented ExpandEnvironmentStringsForUserA/W

svn path=/trunk/; revision=20612
This commit is contained in:
Thomas Bluemel 2006-01-06 15:42:12 +00:00
parent a56d746326
commit 59921c5d0a
2 changed files with 124 additions and 0 deletions

View file

@ -394,4 +394,126 @@ DestroyEnvironmentBlock (LPVOID lpEnvironment)
return TRUE;
}
BOOL WINAPI
ExpandEnvironmentStringsForUserW(IN HANDLE hToken,
IN LPCWSTR lpSrc,
OUT LPWSTR lpDest,
IN DWORD dwSize)
{
PVOID lpEnvironment;
BOOL Ret = FALSE;
if (lpSrc == NULL || lpDest == NULL || dwSize == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (CreateEnvironmentBlock(&lpEnvironment,
hToken,
FALSE))
{
UNICODE_STRING SrcU, DestU;
NTSTATUS Status;
/* initialize the strings */
RtlInitUnicodeString(&SrcU,
lpSrc);
DestU.Length = 0;
DestU.MaximumLength = dwSize * sizeof(WCHAR);
DestU.Buffer = lpDest;
/* expand the strings */
Status = RtlExpandEnvironmentStrings_U((PWSTR)lpEnvironment,
&SrcU,
&DestU,
NULL);
DestroyEnvironmentBlock(lpEnvironment);
if (NT_SUCCESS(Status))
{
Ret = TRUE;
}
else
{
SetLastError(RtlNtStatusToDosError(Status));
}
}
return Ret;
}
BOOL WINAPI
ExpandEnvironmentStringsForUserA(IN HANDLE hToken,
IN LPCSTR lpSrc,
OUT LPSTR lpDest,
IN DWORD dwSize)
{
DWORD dwSrcLen;
LPWSTR lpSrcW = NULL, lpDestW = NULL;
BOOL Ret = FALSE;
if (lpSrc == NULL || lpDest == NULL || dwSize == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
dwSrcLen = strlen(lpSrc);
lpSrcW = (LPWSTR)GlobalAlloc(GMEM_FIXED,
(dwSrcLen + 1) * sizeof(WCHAR));
if (lpSrcW == NULL ||
MultiByteToWideChar(CP_ACP,
0,
lpSrc,
-1,
lpSrcW,
dwSrcLen + 1) == 0)
{
goto Cleanup;
}
lpDestW = (LPWSTR)GlobalAlloc(GMEM_FIXED,
dwSize * sizeof(WCHAR));
if (lpDestW == NULL)
{
goto Cleanup;
}
Ret = ExpandEnvironmentStringsForUserW(hToken,
lpSrcW,
lpDestW,
dwSize);
if (Ret)
{
if (WideCharToMultiByte(CP_ACP,
0,
lpDestW,
-1,
lpDest,
dwSize,
NULL,
NULL) == 0)
{
Ret = FALSE;
}
}
Cleanup:
if (lpSrcW != NULL)
{
GlobalFree((HGLOBAL)lpSrcW);
}
if (lpDestW != NULL)
{
GlobalFree((HGLOBAL)lpDestW);
}
return Ret;
}
/* EOF */

View file

@ -19,6 +19,8 @@ DeleteDesktopItemA@8 @115 NONAME
DeleteDesktopItemW@8 @116 NONAME
CreateEnvironmentBlock@12
DestroyEnvironmentBlock@4
ExpandEnvironmentStringsForUserA@16
ExpandEnvironmentStringsForUserW@16
GetAllUsersProfileDirectoryA@8
GetAllUsersProfileDirectoryW@8
GetDefaultUserProfileDirectoryA@8