Expand the value if we have a REG_EXPAND_SZ entry
authorHervé Poussineau <hpoussin@reactos.org>
Thu, 22 Dec 2005 13:54:07 +0000 (13:54 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Thu, 22 Dec 2005 13:54:07 +0000 (13:54 +0000)
svn path=/trunk/; revision=20299

reactos/subsys/system/services/config.c

index 321949d..8e23f92 100644 (file)
@@ -231,6 +231,8 @@ ScmReadString(HKEY hServiceKey,
     DWORD dwError;\r
     DWORD dwSize;\r
     DWORD dwType;\r
+    DWORD dwSizeNeeded;\r
+    LPWSTR expanded = NULL;\r
     LPBYTE ptr = NULL;\r
 \r
     *lpValue = NULL;\r
@@ -260,9 +262,22 @@ ScmReadString(HKEY hServiceKey,
 \r
     if (dwType == REG_EXPAND_SZ)\r
     {\r
-        /* FIXME: ... */\r
-        DPRINT1("Expand me!\n");\r
-        *lpValue = (LPWSTR)ptr;\r
+        /* Expand the value... */\r
+        dwSizeNeeded = ExpandEnvironmentStringsW((LPCWSTR)ptr, NULL, 0);\r
+        if (dwSizeNeeded == 0)\r
+        {\r
+            dwError = GetLastError();\r
+            goto done;\r
+        }\r
+        expanded = HeapAlloc(GetProcessHeap(), 0, dwSizeNeeded);\r
+        if (dwSizeNeeded < ExpandEnvironmentStringsW((LPCWSTR)ptr, expanded, dwSizeNeeded))\r
+        {\r
+            dwError = GetLastError();\r
+            goto done;\r
+        }\r
+        *lpValue = expanded;\r
+        HeapFree(GetProcessHeap(), 0, ptr);\r
+        dwError = ERROR_SUCCESS;\r
     }\r
     else\r
     {\r
@@ -271,7 +286,10 @@ ScmReadString(HKEY hServiceKey,
 \r
 done:;\r
     if (dwError != ERROR_SUCCESS)\r
+    {\r
         HeapFree(GetProcessHeap(), 0, ptr);\r
+        HeapFree(GetProcessHeap(), 0, expanded);\r
+    }\r
 \r
     return dwError;\r
 }\r