From 3b4801c5e5f25f1b64ecb0b5b473c25c58f7a153 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 25 Jan 2005 19:02:08 +0000 Subject: [PATCH] Implement DuplicateString and QueryRegistryValue. --- dlls/setupapi/misc.c | 81 +++++++++++++++++++++++++++++++++++++ dlls/setupapi/setupapi.spec | 4 +- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/dlls/setupapi/misc.c b/dlls/setupapi/misc.c index 277276a6c7a..dfbe49bb047 100644 --- a/dlls/setupapi/misc.c +++ b/dlls/setupapi/misc.c @@ -27,6 +27,8 @@ #include "winreg.h" #include "setupapi.h" +#include "wine/unicode.h" + /************************************************************************** * MyFree [SETUPAPI.@] @@ -91,3 +93,82 @@ LPVOID WINAPI MyRealloc(LPVOID lpSrc, DWORD dwSize) return HeapReAlloc(GetProcessHeap(), 0, lpSrc, dwSize); } + + +/************************************************************************** + * DuplicateString [SETUPAPI.@] + * + * Duplicates a unicode string. + * + * PARAMS + * lpSrc [I] pointer to the unicode string that will be duplicated + * + * RETURNS + * Success: pointer to the duplicated unicode string + * Failure: NULL + * + * NOTES + * Call MyFree() to release the duplicated string. + */ + +LPWSTR WINAPI DuplicateString(LPCWSTR lpSrc) +{ + LPWSTR lpDst; + + lpDst = MyMalloc((lstrlenW(lpSrc) + 1) * sizeof(WCHAR)); + if (lpDst == NULL) + return NULL; + + strcpyW(lpDst, lpSrc); + + return lpDst; +} + + +/************************************************************************** + * QueryRegistryValue [SETUPAPI.@] + * + * Retrieves value data from the registry and allocates memory for the + * value data. + * + * PARAMS + * hKey [I] Handle of the key to query + * lpValueName [I] Name of value under hkey to query + * lpData [O] Destination for the values contents, + * lpType [O] Destination for the value type + * lpcbData [O] Destination for the size of data + * + * RETURNS + * Success: ERROR_SUCCESS + * Failure: Otherwise + * + * NOTES + * Use MyFree to release the lpData buffer. + */ + +LONG WINAPI QueryRegistryValue(HKEY hKey, + LPCWSTR lpValueName, + LPBYTE *lpData, + LPDWORD lpType, + LPDWORD lpcbData) +{ + LONG lError; + + /* Get required buffer size */ + *lpcbData = 0; + lError = RegQueryValueExW(hKey, lpValueName, 0, lpType, NULL, lpcbData); + if (lError != ERROR_SUCCESS) + return lError; + + /* Allocate buffer */ + *lpData = MyMalloc(*lpcbData); + if (*lpData == NULL) + return ERROR_NOT_ENOUGH_MEMORY; + + /* Query registry value */ + lError = RegQueryValueExW(hKey, lpValueName, 0, lpType, *lpData, lpcbData); + if (lError != ERROR_SUCCESS) + MyFree(*lpData); + + return lError; +} diff --git a/dlls/setupapi/setupapi.spec b/dlls/setupapi/setupapi.spec index 88fa12b5d6b..22a164c6716 100644 --- a/dlls/setupapi/setupapi.spec +++ b/dlls/setupapi/setupapi.spec @@ -198,7 +198,7 @@ @ stub DelimStringToMultiSz @ stub DestroyTextFileReadBuffer @ stub DoesUserHavePrivilege -@ stub DuplicateString +@ stdcall DuplicateString(wstr) @ stub EnablePrivilege @ stub ExtensionPropSheetPageProc @ stub FileExists @@ -226,7 +226,7 @@ @ stub OpenAndMapFileForRead @ stub OutOfMemory @ stub QueryMultiSzValueToArray -@ stub QueryRegistryValue +@ stdcall QueryRegistryValue(long wstr ptr ptr ptr) @ stub ReadAsciiOrUnicodeTextFile @ stub RegistryDelnode @ stub RetreiveFileSecurity