/*
* PerformanceCounterPathExpander.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL9
// 2009/09/30
#pragma once
#include <sol/String.h>
#include <sol/pdh/PdhObject.h>
namespace SOL {
class PerformanceCounterPathExpander :public PdhObject {
private:
TCHAR* counterPath;
public:
PerformanceCounterPathExpander(const TCHAR* path=NULL)
:counterPath(NULL)
{
clear();
if (path) {
expand(path);
}
}
public:
~PerformanceCounterPathExpander()
{
clear();
}
public:
void clear()
{
if (counterPath) {
delete [] counterPath;
counterPath = NULL;
}
}
public:
DWORD expand(const TCHAR* wildCardPath)
{
clear();
DWORD dwPathSize = 0;
PDH_STATUS status= PdhExpandCounterPath(wildCardPath, NULL,
&dwPathSize);
if (status != PDH_MORE_DATA) {
throw (int)status;
}
//printf("Size ~%d\n", dwCtrPathSize);
dwPathSize += 1;
counterPath = new TCHAR[dwPathSize];
status = PdhExpandCounterPath(wildCardPath, counterPath,
&dwPathSize);
if (status != PDH_CSTATUS_VALID_DATA) {
throw (int)status;
}
return status;
}
public:
void display()
{
const TCHAR* p = counterPath;
while (*p) {
_tprintf(_T("%s\n"), p);
p += strlen(p) + 1;
}
}
};
}
|