Platform SDK: Performance Monitoring

PdhOpenQuery

The PdhOpenQuery function creates and initializes a unique query structure that is used to manage the collection of performance data.

PDH_STATUS PdhOpenQuery(
  LPCTSTR szDataSource,  
  DWORD_PTR dwUserData,  
  HQUERY *phQuery        
);

Parameters

szDataSource
Windows 2000: [in] A pointer to a null-terminated string containing either the name of a log file or the null termination only. If you specify the name of a log file, performance data will be taken from that log file. If this parameter contains only a NULL, performance data will be taken from a real-time data source.

Windows NT 4.0: Reserved. Must be NULL.

dwUserData
[in] A user-defined value that is to be associated with this query.
phQuery
[out] A pointer to the buffer that receives a handle to the query that is created.

Return Values

If the function succeeds, it returns ERROR_SUCCESS, creates a new query, and returns a handle to the query in the buffer pointed to by phQuery.

If the function fails, the return value is a PDH error status defined in PDHMsg.h. The following are possible error values.

Error value Description
PDH_INVALID_ARGUMENT One or more arguments are invalid.
PDH_MEMORY_ALLOCATION_FAILURE A memory buffer could not be allocated.

Remarks

You can call PdhGetCounterInfo to retrieve the user data value set by dwUserData.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Header: Declared in Pdh.h.
  Library: Use Pdh.lib.

See Also

PdhCloseQuery, PdhGetCounterInfo