Paul Vriens : advapi32/service:
Forward GetServiceDisplayNameA to GetServiceDisplayNameW.
Alexandre Julliard
julliard at wine.codeweavers.com
Fri Jul 27 07:34:49 CDT 2007
Module: wine
Branch: master
Commit: 95d2f0461148dbec7f48ed23b6889329757b89ab
URL: http://source.winehq.org/git/wine.git/?a=commit;h=95d2f0461148dbec7f48ed23b6889329757b89ab
Author: Paul Vriens <paul.vriens.wine at gmail.com>
Date: Thu Jul 26 16:09:37 2007 +0200
advapi32/service: Forward GetServiceDisplayNameA to GetServiceDisplayNameW.
---
dlls/advapi32/service.c | 61 ++++++++++++++++++++++-------------------
dlls/advapi32/tests/service.c | 8 +-----
2 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c
index 1ecaf70..bee4847 100644
--- a/dlls/advapi32/service.c
+++ b/dlls/advapi32/service.c
@@ -2266,45 +2266,50 @@ BOOL WINAPI QueryServiceLockStatusW( SC_HANDLE hSCManager,
BOOL WINAPI GetServiceDisplayNameA( SC_HANDLE hSCManager, LPCSTR lpServiceName,
LPSTR lpDisplayName, LPDWORD lpcchBuffer)
{
- struct sc_manager *hscm;
- DWORD type, size;
- LONG ret;
+ LPWSTR lpServiceNameW, lpDisplayNameW = NULL;
+ DWORD size, sizeW, GLE;
+ BOOL ret;
TRACE("%p %s %p %p\n", hSCManager,
debugstr_a(lpServiceName), lpDisplayName, lpcchBuffer);
- hscm = sc_handle_get_handle_data(hSCManager, SC_HTYPE_MANAGER);
- if (!hscm)
+ lpServiceNameW = SERV_dup(lpServiceName);
+ lpDisplayNameW = HeapAlloc(GetProcessHeap(), 0, *lpcchBuffer * sizeof(WCHAR));
+
+ size = sizeW = *lpcchBuffer;
+ ret = GetServiceDisplayNameW(hSCManager, lpServiceNameW,
+ lpDisplayName ? lpDisplayNameW : NULL,
+ &sizeW);
+ /* Last error will be set by GetServiceDisplayNameW and must be preserved */
+ GLE = GetLastError();
+
+ if (!lpDisplayName && lpcchBuffer && !ret && (GLE == ERROR_INSUFFICIENT_BUFFER))
{
- SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
+ /* Request for buffersize.
+ *
+ * Only set the size for ERROR_INSUFFICIENT_BUFFER
+ */
+ size = sizeW * 2;
}
-
- if (!lpServiceName)
+ else if (lpDisplayName && lpcchBuffer && !ret)
{
- SetLastError(ERROR_INVALID_ADDRESS);
- return FALSE;
+ /* Request for displayname.
+ *
+ * size only has to be set if this fails
+ */
+ size = sizeW * 2;
}
- size = *lpcchBuffer;
- ret = RegGetValueA(hscm->hkey, lpServiceName, "DisplayName", RRF_RT_REG_SZ, &type, lpDisplayName, &size);
- if (!ret && !lpDisplayName && size)
- ret = ERROR_MORE_DATA;
+ WideCharToMultiByte(CP_ACP, 0, lpDisplayNameW, (sizeW + 1), lpDisplayName,
+ *lpcchBuffer, NULL, NULL );
- if (ret)
- {
- if (lpDisplayName && *lpcchBuffer) *lpDisplayName = 0;
+ *lpcchBuffer = size;
- if (ret == ERROR_MORE_DATA)
- {
- SetLastError(ERROR_INSUFFICIENT_BUFFER);
- *lpcchBuffer = size - 1;
- }
- else
- SetLastError(ret);
- return FALSE;
- }
- return TRUE;
+ HeapFree(GetProcessHeap(), 0, lpDisplayNameW);
+ SERV_free(lpServiceNameW);
+
+ SetLastError(GLE);
+ return ret;
}
/******************************************************************************
diff --git a/dlls/advapi32/tests/service.c b/dlls/advapi32/tests/service.c
index cf01726..77fc85a 100644
--- a/dlls/advapi32/tests/service.c
+++ b/dlls/advapi32/tests/service.c
@@ -459,24 +459,19 @@ static void test_get_displayname(void)
SetLastError(0xdeadbeef);
displaysize = (tempsize / 2) + 1;
ret = GetServiceDisplayNameA(scm_handle, spooler, displayname, &displaysize);
- todo_wine
- {
ok(ret, "Expected success\n");
ok(displaysize == ((tempsize / 2) + 1), "Expected no change for the needed buffer size\n");
ok(GetLastError() == ERROR_SUCCESS /* W2K3 */ ||
GetLastError() == ERROR_IO_PENDING /* W2K */ ||
GetLastError() == 0xdeadbeef /* NT4, XP, Vista */,
"Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
- }
/* Now with the original returned size */
SetLastError(0xdeadbeef);
displaysize = tempsize;
ret = GetServiceDisplayNameA(scm_handle, spooler, displayname, &displaysize);
- todo_wine
ok(ret, "Expected success\n");
ok(displaysize == tempsize, "Expected no change for the needed buffer size\n");
- todo_wine
ok(GetLastError() == ERROR_SUCCESS /* W2K3 */ ||
GetLastError() == ERROR_IO_PENDING /* W2K */ ||
GetLastError() == 0xdeadbeef /* NT4, XP, Vista */,
@@ -493,7 +488,6 @@ static void test_get_displayname(void)
"Expected ERROR_SUCCESS, ERROR_IO_PENDING or 0xdeadbeef, got %d\n", GetLastError());
/* Test that shows that if the buffersize is enough, it's not changed */
ok(displaysize == tempsize * 2, "Expected no change for the needed buffer size\n");
- todo_wine
ok(lstrlen(displayname) == tempsize/2,
"Expected the buffer to be twice the length of the string\n") ;
@@ -538,9 +532,9 @@ static void test_get_displayname(void)
ok(displaysize == tempsizeW, "Expected the needed buffersize\n");
ok(lstrlenW(displaynameW) == displaysize,
"Expected the buffer to be the length of the string\n") ;
+ }
ok(tempsize / 2 == tempsizeW,
"Expected the needed buffersize (in bytes) to be the same for the A and W call\n");
- }
CloseServiceHandle(scm_handle);
More information about the wine-cvs
mailing list