implemented ExpandEnvironmentStringsForUserA/W
authorThomas Bluemel <thomas@reactsoft.com>
Fri, 6 Jan 2006 15:42:12 +0000 (15:42 +0000)
committerThomas Bluemel <thomas@reactsoft.com>
Fri, 6 Jan 2006 15:42:12 +0000 (15:42 +0000)
svn path=/trunk/; revision=20612

reactos/lib/userenv/environment.c
reactos/lib/userenv/userenv.def

index e0da99d..8e378bf 100644 (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 */
index bd4cdda..7d29009 100644 (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