获取PDH性能对象的列表之二------------获取Windows所有性能对象

#define _UNICODE /*主要对C标准库函数,将宏替换为宽字节形式*/
#define UNICODE /*主要对Windows API标准函数,将函数宏替换为宽字节形式*/
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include <malloc.h>
#include <stdio.h>
#include <pdh.h>
#include <pdhmsg.h> /*存放PDH函数返回的错误代码*/
#include <tchar.h> ///

#pragma comment(lib, "pdh.lib")
void main(void)
{
    LPTSTR pTemp = NULL;
    PDH_STATUS status = ERROR_SUCCESS;
    LPTSTR strBuffer=NULL;
    DWORD BufferLength=0;
    /*第一次调用,将返回实际的字符数*/
    status = PdhEnumObjects(
    		NULL,				// real-time source
			NULL,				// local machine
			strBuffer,         // LPTSTR mszObjectList
			&BufferLength,   //LPDWORD pcchBufferLength,
			PERF_DETAIL_EXPERT,     //DWORD dwDetailLevel
			FALSE//BOOL bRefresh
    );
    /*读取性能对象列表*/
    if (status == PDH_MORE_DATA){
        // Allocate the buffers and try the call again.
    	strBuffer=(LPTSTR)malloc(BufferLength * sizeof(TCHAR));
        if (NULL != strBuffer ){
            status = PdhEnumObjects(
            		NULL,// real-time source
        			NULL,// local machine
        			strBuffer,         // LPTSTR mszObjectList
        			&BufferLength,   //LPDWORD pcchBufferLength,
        			PERF_DETAIL_EXPERT,     //DWORD dwDetailLevel
        			FALSE//BOOL bRefresh
            );
            if (status == ERROR_SUCCESS){
                for (pTemp =strBuffer; *pTemp != 0; pTemp +=_tcslen(pTemp)+1)
                	/*从字符数组中读取字符串的方法*/
                {
                	_tprintf(_T("%s\n"),pTemp);
                     //wprintf(L"%s\n", pTemp);
                }
            }else{
            	_tprintf(_T("Second PdhEnumObjects failed with %0x%x.\n"), status);
                //wprintf(L"Second PdhEnumObjects failed with %0x%x.\n", status);
            }
        }else{
        	_tprintf(_T("Unable to allocate buffers.\n"));
            //wprintf(L"Unable to allocate buffers.\n");
            status = ERROR_OUTOFMEMORY;
        }
    }else{
    	_tprintf(_T("\nPdhEnumObjects failed with 0x%x.\n"), status);
        //wprintf(L"\nPdhEnumObjects failed with 0x%x.\n", status);
    }
    if (strBuffer != NULL)
        free (strBuffer);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值