这个程序在vc.net为什么编译通不过?请高手帮忙啊!
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <stdio.h>
#include <malloc.h>
#include <tchar.h>
#include <pdhmsg.h>
#include <pdh.h>
#define BROWSER_COUNTER_PATH_SIZE 8196
#define MAX_COUNTERS 100
// This structure is defined so that the caller of
// PdhBrowseCounters can pass information to the
// callback function that is called once for each
// "Add" click.
typedef struct {
LPTSTR lpszCounterPath;
HQUERY hQuery;
HCOUNTER *ahCounters;
DWORD dwMaxCounters;
DWORD dwIndexCount;
} PDH_BROWSE_COUNTER_ARGS, *PPDH_BROWSE_COUNTER_ARGS;
// prototypes for functions defined in this source
void print_pdh_error(
LPTSTR lpszFuncName,
PDH_STATUS pdhStatus
);
BOOL get_cmd_args(
int argc,
TCHAR **argv,
LPTSTR *lppszInfile,
LPTSTR *lppszOutfile,
LPDWORD lpdwOutFileType
);
void print_usage(LPTSTR lpszAppName);
void print_copyright(void);
PDH_STATUS WINAPI pdhBrowseCallback(
DWORD dwArg
);
// -----------------------------------------------------------------------
// FUNCTION: _tmain
//
// The main routine contains the bulk of the algorithm of transferring
// data from one log file and placing it into another performance log.
//
// The procedure for doing so is
// open source log using a query
// add counters to the query
// open the destination log file and refer to the query
// for each data sample in the source log
// read a data sample and write it to the output log
// close both log files.
// -----------------------------------------------------------------------
void __cdecl _tmain(int argc, TCHAR **argv)
{
PDH_BROWSE_DLG_CONFIG BrowseInfo;
TCHAR szCounterBuffer[BROWSER_COUNTER_PATH_SIZE];
PDH_STATUS pdhStatus = 0;
HLOG hLog = NULL;
HQUERY hQuery = NULL;
HCOUNTER ahCounters[MAX_COUNTERS];
PDH_BROWSE_COUNTER_ARGS pdhCallbackArgs;
LPTSTR lpszInfile = NULL;
LPTSTR lpszOutfile = NULL;
DWORD dwOutFileType = 0;
DWORD dwNumEntries = 0;
DWORD dwBuffSize = 0;
PDH_TIME_INFO pdhTimeRange;
DWORD i;
print_copyright();
if (
!get_cmd_args(argc, argv, &lpszInfile,
&lpszOutfile, &dwOutFileType)
)
{
print_usage(argv[0]);
return;
}
memset(szCounterBuffer,0,BROWSER_COUNTER_PATH_SIZE * sizeof(TCHAR));
memset(ahCounters, 0, MAX_COUNTERS * sizeof(HCOUNTER));
memset(&pdhCallbackArgs, 0, sizeof(PDH_BROWSE_COUNTER_ARGS));
memset(&pdhTimeRange, 0, sizeof(PDH_TIME_INFO));
pdhStatus = PdhOpenQuery(lpszInfile, 0, &hQuery);
if (IsErrorSeverity(pdhStatus))
{
print_pdh_error(TEXT("PdhOpenQuery"), pdhStatus);
return;
}
// setup the args for the browse callback
pdhCallbackArgs.hQuery = hQuery;
pdhCallbackArgs.ahCounters = ahCounters;
pdhCallbackArgs.dwMaxCounters = MAX_COUNTERS;
pdhCallbackArgs.dwIndexCount = 0;
pdhCallbackArgs.lpszCounterPath = szCounterBuffer;
memset(&BrowseInfo, 0, sizeof(BrowseInfo));
BrowseInfo.bReserved = 0;
BrowseInfo.bIncludeInstanceIndex = FALSE;
BrowseInfo.bSingleCounterPerAdd = FALSE;
BrowseInfo.bSingleCounterPerDialog = FALSE;
BrowseInfo.bLocalCountersOnly = FALSE;
BrowseInfo.bWildCardInstances = FALSE;
BrowseInfo.bHideDetailBox = TRUE;
BrowseInfo.bDisableMachineSelection = FALSE;
BrowseInfo.bInitializePath = FALSE;
BrowseInfo.bIncludeCostlyObjects = FALSE;
BrowseInfo.hWndOwner = NULL;
BrowseInfo.szReturnPathBuffer = szCounterBuffer;
BrowseInfo.cchReturnPathLength = BROWSER_COUNTER_PATH_SIZE;
BrowseInfo.pCallBack = pdhBrowseCallback;
BrowseInfo.dwCallBackArg = (DWORD)&pdhCallbackArgs;
BrowseInfo.CallBackStatus = ERROR_SUCCESS;
BrowseInfo.dwDefaultDetailLevel = PERF_DETAIL_WIZARD;
BrowseInfo.szDialogBoxCaption = TEXT("Select counters from log file");
BrowseInfo.szDataSource = (LPTSTR)lpszInfile;
pdhStatus = PdhBrowseCounters (&BrowseInfo);
if (IsErrorSeverity(pdhStatus))
{
PdhCloseQuery(hQuery);
print_pdh_error(TEXT("PdhBrowseCounters"), pdhStatus);
return;
}
pdhStatus = PdhOpenLog(
lpszOutfile,
PDH_LOG_WRITE_ACCESS | PDH_LOG_CREATE_ALWAYS,
&dwOutFileType,
hQuery, // links the input file to output file
0,
NULL, // no user caption
&hLog
);
if (IsErrorSeverity(pdhStatus))
{
PdhCloseQuery(hQuery);
print_pdh_error(TEXT("PdhOpenLog"), pdhStatus);
return;
}
// now do the transfer from the hQuery to the hLog
// this will loop until all datapoint from the
// input log file is exhausted
// Typically, you can call PdhUpdateLog until
// the all of the records of the input log have
// been read. But in my experience PdhUpdateLog
// may fail for the first record or two on some
// perfmon logs. So instead we can get the
// number of data samplings and use a for loop
// Get the time range of the input log data.
// This also retrieves the number sample count
// which is the number of records in the log file
dwBuffSize = sizeof(PDH_TIME_INFO);
pdhStatus = PdhGetDataSourceTimeRange(lpszInfile,
&dwNumEntries,
&pdhTimeRange,
&dwBuffSize);
// PdhUpdateLog will get the data from the hQuery
// and write it to the output log
for (i=0; i<pdhTimeRange.SampleCount; i++)
pdhStatus = PdhUpdateLog(hLog, NULL);
pdhStatus = PdhUpdateLogFileCatalog(hLog);
if (IsErrorSeverity(pdhStatus))
{
print_pdh_error(TEXT("PdhUpdateLogFileCatalog"), pdhStatus);
}
PdhCloseLog(hLog, 0);
PdhCloseQuery(hQuery);
}