Platform SDK: Performance Monitoring

PdhGetDefaultPerfCounter

The PdhGetDefaultPerfCounter function retrieves the name of the default counter for the specified object. This name can be used to set the initial selection of the counter browser list/combo box.

PDH_STATUS PdhGetDefaultPerfCounter(
  LPCTSTR szDataSource,        
  LPCTSTR szMachineName,       
  LPCTSTR szObjectName,        
  LPTSTR szDefaultCounterName, 
  LPDWORD pcchBufferSize       
);

Parameters

szDataSource
Windows 2000: [in] A pointer to a null-terminated string containing either the name of a log file or a null string. 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 string, performance data will be taken from a real-time data source.

Windows NT 4.0: Reserved. Must be NULL.

szMachineName
[in] A pointer to a null-terminated string containing the name of the machine to query.
szObjectName
[in] A pointer to a null-terminated string containing the name of the object in szMachineName to query.
szDefaultCounterName
[out] A pointer to a null-terminated string containing the name of the buffer that receives the default counter name for the specified object. This parameter can be NULL if the value of the variable referenced by pcchBufferSize is zero.
pcchBufferSize
[in/out] A pointer to a DWORD containing the size of the szDefaultCounterName buffer, in characters, when called, and the size of the counter name returned on return. If the value in the variable pointed to by this parameter is 0, then the required buffer size, in characters, for this object name is returned in the variable and no data is copied to the buffer.

Return Values

If the function succeeds, it returns ERROR_SUCCESS.

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_INSUFFICIENT_BUFFER The buffer provided is not large enough for the available data.
PDH_INVALID_ARGUMENT A required argument is invalid or a reserved argument is not NULL.
PDH_MEMORY_ALLOCATION_FAILURE A required temporary buffer could not be allocated.
PDH_CSTATUS_NO_MACHINE The specified machine is offline or unavailable.
PDH_CSTATUS_NO_COUNTERNAME The default object name cannot be read or found.
PDH_CSTATUS_NO_OBJECT The specified object could not be found on the specified machine.
PDH_CSTATUS_NO_COUNTER The default counter was not found in the specified object.

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Header: Declared in Pdh.h.
  Library: Use Pdh.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

PdhGetDefaultPerfObject