Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54618
If the handle passed is `(void *)0xdeadbeef` it crashes in Wine, but not in Windows. I'm guessing this is not very important.
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54618 --- dlls/pdh/pdh.spec | 2 +- dlls/pdh/pdh_main.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/dlls/pdh/pdh.spec b/dlls/pdh/pdh.spec index 5f61a8a42ca..711c970029b 100644 --- a/dlls/pdh/pdh.spec +++ b/dlls/pdh/pdh.spec @@ -145,7 +145,7 @@ @ stub PdhVbCreateCounterPathList @ stub PdhVbGetCounterPathElements @ stub PdhVbGetCounterPathFromList -@ stub PdhVbGetDoubleCounterValue +@ stdcall PdhVbGetDoubleCounterValue(ptr ptr) @ stub PdhVbGetLogFileSize @ stub PdhVbGetOneCounterPath @ stub PdhVbIsGoodStatus diff --git a/dlls/pdh/pdh_main.c b/dlls/pdh/pdh_main.c index 7eae7872b48..483ad8ffccb 100644 --- a/dlls/pdh/pdh_main.c +++ b/dlls/pdh/pdh_main.c @@ -1062,6 +1062,22 @@ PDH_STATUS WINAPI PdhVbAddCounter( PDH_HQUERY query, LPCSTR path, PDH_HCOUNTER * return PDH_NOT_IMPLEMENTED; }
+/*********************************************************************** + * PdhVbGetDoubleCounterValue (PDH.@) + */ +double WINAPI PdhVbGetDoubleCounterValue( PDH_HCOUNTER handle, PDH_STATUS *counter_status ) +{ + PDH_FMT_COUNTERVALUE value; + PDH_STATUS status; + + TRACE( "%p %p\n", handle, counter_status ); + + status = PdhGetFormattedCounterValue( handle, PDH_FMT_DOUBLE, NULL, &value ); + if (counter_status) *counter_status = ( status == ERROR_SUCCESS ) ? value.CStatus : status; + + return ( status == ERROR_SUCCESS ) ? value.u.doubleValue : 0.0; +} + /*********************************************************************** * PdhValidatePathExA (PDH.@) */
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/pdh/tests/pdh.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
diff --git a/dlls/pdh/tests/pdh.c b/dlls/pdh/tests/pdh.c index 195fd89eba5..23db2acc396 100644 --- a/dlls/pdh/tests/pdh.c +++ b/dlls/pdh/tests/pdh.c @@ -34,6 +34,7 @@ static PDH_STATUS (WINAPI *pPdhAddEnglishCounterW)(PDH_HQUERY, LPCWSTR, DWORD_ static PDH_STATUS (WINAPI *pPdhCollectQueryDataWithTime)(PDH_HQUERY, LONGLONG *); static PDH_STATUS (WINAPI *pPdhValidatePathExA)(PDH_HLOG, LPCSTR); static PDH_STATUS (WINAPI *pPdhValidatePathExW)(PDH_HLOG, LPCWSTR); +static double (WINAPI *pPdhVbGetDoubleCounterValue)(PDH_HCOUNTER, PDH_STATUS *);
#define GETFUNCPTR(func) p##func = (void *)GetProcAddress( pdh, #func );
@@ -69,6 +70,7 @@ static void init_function_ptrs( void ) GETFUNCPTR( PdhCollectQueryDataWithTime ) GETFUNCPTR( PdhValidatePathExA ) GETFUNCPTR( PdhValidatePathExW ) + GETFUNCPTR( PdhVbGetDoubleCounterValue ) }
static const WCHAR processor_time[] = L"% Processor Time"; @@ -424,6 +426,44 @@ static void test_PdhGetRawCounterValue( void ) ok(ret == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", ret); }
+static void test_PdhVbGetDoubleCounterValue(void) +{ + PDH_FMT_COUNTERVALUE value; + PDH_HCOUNTER counter; + PDH_STATUS status; + PDH_HQUERY query; + double ret; + + status = PdhOpenQueryA( NULL, 0, &query ); + ok(status == ERROR_SUCCESS, "PdhOpenQueryA failed 0x%08lx\n", status); + + status = PdhAddCounterA( query, "\System\System Up Time", 0, &counter ); + ok(status == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", status); + + status = PdhCollectQueryData(query); + ok(status == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", status); + + status = PdhGetFormattedCounterValue( counter, PDH_FMT_DOUBLE, NULL, &value ); + ok(status == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", status); + + ret = pPdhVbGetDoubleCounterValue( NULL, NULL ); + ok(ret == 0.0, "Unexpected value %f\n", ret); + + ret = pPdhVbGetDoubleCounterValue( NULL, &status ); + ok(status == PDH_INVALID_HANDLE, "PdhVbGetDoubleCounterValue failed 0x%08lx\n", status); + ok(ret == 0.0, "Unexpected value %f\n", ret); + + ret = pPdhVbGetDoubleCounterValue( counter, NULL ); + ok(ret == value.doubleValue, "Unexpected value %f\n", ret); + + ret = pPdhVbGetDoubleCounterValue( counter, &status ); + ok(status == ERROR_SUCCESS, "PdhVbGetDoubleCounterValue failed 0x%08lx\n", status); + ok(ret == value.doubleValue, "Unexpected value %f\n", ret); + + status = PdhCloseQuery(query); + ok(status == ERROR_SUCCESS, "PdhCloseQuery failed 0x%08lx\n", status); +} + static void test_PdhSetCounterScaleFactor( void ) { PDH_STATUS ret; @@ -998,6 +1038,8 @@ START_TEST(pdh) test_PdhSetCounterScaleFactor(); test_PdhGetCounterTimeBase();
+ test_PdhVbGetDoubleCounterValue(); + test_PdhGetCounterInfoA(); test_PdhGetCounterInfoW();
Hans Leidekker (@hans) commented about dlls/pdh/pdh_main.c:
+/***********************************************************************
PdhVbGetDoubleCounterValue (PDH.@)
- */
+double WINAPI PdhVbGetDoubleCounterValue( PDH_HCOUNTER handle, PDH_STATUS *counter_status ) +{
- PDH_FMT_COUNTERVALUE value;
- PDH_STATUS status;
- TRACE( "%p %p\n", handle, counter_status );
- status = PdhGetFormattedCounterValue( handle, PDH_FMT_DOUBLE, NULL, &value );
- if (counter_status) *counter_status = ( status == ERROR_SUCCESS ) ? value.CStatus : status;
- return ( status == ERROR_SUCCESS ) ? value.u.doubleValue : 0.0;
+}
This could be simplified like this: `` double WINAPI PdhVbGetDoubleCounterValue( PDH_HCOUNTER handle, PDH_STATUS *counter_status ) { PDH_FMT_COUNTERVALUE value; PDH_STATUS status;
TRACE( "%p %p\n", handle, counter_status );
memset( &value, 0, sizeof(value) ); status = PdhGetFormattedCounterValue( handle, PDH_FMT_DOUBLE, NULL, &value ); if (counter_status) *counter_status = status; return value.u.doubleValue; } ``
Hans Leidekker (@hans) commented about dlls/pdh/tests/pdh.c:
- status = PdhAddCounterA( query, "\System\System Up Time", 0, &counter );
- ok(status == ERROR_SUCCESS, "PdhAddCounterA failed 0x%08lx\n", status);
- status = PdhCollectQueryData(query);
- ok(status == ERROR_SUCCESS, "PdhCollectQueryData failed 0x%08lx\n", status);
- status = PdhGetFormattedCounterValue( counter, PDH_FMT_DOUBLE, NULL, &value );
- ok(status == ERROR_SUCCESS, "PdhGetFormattedCounterValue failed 0x%08lx\n", status);
- ret = pPdhVbGetDoubleCounterValue( NULL, NULL );
- ok(ret == 0.0, "Unexpected value %f\n", ret);
- ret = pPdhVbGetDoubleCounterValue( NULL, &status );
- ok(status == PDH_INVALID_HANDLE, "PdhVbGetDoubleCounterValue failed 0x%08lx\n", status);
- ok(ret == 0.0, "Unexpected value %f\n", ret);
You should set 'status' to a known value before calling PdhVbGetDoubleCounterValue(). Same below.