Re: Problem with double byte
- From: sundaram.babu@xxxxxxxxx
- Date: Mon, 3 Dec 2007 20:52:04 -0800 (PST)
Hi
Thanks for your reply.
Changed the settings and code as you said. The modified code is given
below
// TestApp.cpp : Defines the entry point for the console application.
//
#ifdef UNICODE
#ifndef _UNICODE
#define _UNICODE 1
#endif
#include "stdafx.h"
#include <windows.h>
#include <winperf.h>
#include <malloc.h>
#include <stdio.h>
#include <tchar.h>
#include <pdh.h>
#include <pdhmsg.h>
#include <stdlib.h>
int _tmain()
{
PDH_STATUS pdhStatus = ERROR_SUCCESS;
LPTSTR szCounterListBuffer = NULL;
DWORD dwCounterListSize = 0;
LPTSTR szInstanceListBuffer = NULL;
DWORD dwInstanceListSize = 0;
LPCTSTR szThisInstance = NULL;
// Determine the required buffer size for the data.
pdhStatus = PdhEnumObjectItems (
NULL, // real time source
NULL, // local machine
TEXT("Process"), // object to enumerate
szCounterListBuffer, // pass NULL and 0
&dwCounterListSize, // to get length required
szInstanceListBuffer, // buffer size
&dwInstanceListSize, //
PERF_DETAIL_WIZARD, // counter detail level
0);
if (pdhStatus == PDH_MORE_DATA || pdhStatus == ERROR_SUCCESS)
{
// Allocate the buffers and try the call again.
szCounterListBuffer = (LPTSTR)malloc (
(dwCounterListSize * sizeof (TCHAR)));
szInstanceListBuffer = (LPTSTR)malloc (
(dwInstanceListSize * sizeof (TCHAR)));
if ((szCounterListBuffer != NULL) &&
(szInstanceListBuffer != NULL))
{
pdhStatus = PdhEnumObjectItems (
NULL, // real time source
NULL, // local machine
TEXT("Process"), // object to enumerate
szCounterListBuffer, // buffer to receive counter
list
&dwCounterListSize,
szInstanceListBuffer, // buffer to receive instance
list
&dwInstanceListSize,
PERF_DETAIL_WIZARD, // counter detail level
0);
if (pdhStatus == ERROR_SUCCESS)
{
_tprintf (TEXT("\nEnumerating Processes:"));
// Walk the instance list. The list can contain one
// or more null-terminated strings. The last string
// is followed by a second null-terminator.
szThisInstance = szInstanceListBuffer;
while(*szThisInstance)
{
_tprintf(TEXT("\n%s"),szThisInstance);
szThisInstance = szThisInstance + _tcslen(szThisInstance);
szThisInstance = _tcsinc(szThisInstance);
}
}
else
{
_tprintf(TEXT("\nPdhEnumObjectItems failed1 with
%ld."), pdhStatus);
}
}
else
{
_tprintf (TEXT("\nUnable to allocate buffers"));
pdhStatus = ERROR_OUTOFMEMORY;
}
if (szCounterListBuffer != NULL)
free (szCounterListBuffer);
if (szInstanceListBuffer != NULL)
free (szInstanceListBuffer);
}
else
{
//_tprintf(TEXT("\nPdhEnumObjectItems failed2 with %ld."),
pdhStatus);
}
return pdhStatus;
}
My project settings under "all configurations" is given below
_UNICODE,UNICODE,WIN32,_CONSOLE
The code compiles and links successfully. But i'm not able to see the
korean process names in the output. Instead, a empty line is coming.
Please help me to solve the issue.
On Dec 4, 10:57 am, "Mihai N." <nmihai_year_2...@xxxxxxxxx> wrote:
Fixes the thing:
in the while(*szThisInstance) loop change
szThisInstance = szThisInstance + _tcslen(szThisInstance) * sizeof(TCHAR);
to
szThisInstance = szThisInstance + _tcslen(szThisInstance);
When you add a number to a pointer, the number is automatically multiplied
with the size of the type.
Other things that you might cleanup:
- Build your project with UNICODE defined
- Usually you define both UNICODE and _UNICODE
http://www.mihai-nita.net/article.php?artID=20060723a
Defining _UNICODE before including stdafx.h, because stuff
declared in stdafx.h might be affected
- No need for tmain, just include <tchar.h> and use _tmain.
- Change szThisInstance to LPCTSTR
--
Mihai Nita [Microsoft MVP, Windows - SDK]http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
.
- Follow-Ups:
- Re: Problem with double byte
- From: Mihai N.
- Re: Problem with double byte
- References:
- Problem with double byte
- From: sundaram . babu
- Re: Problem with double byte
- From: Mihai N.
- Problem with double byte
- Prev by Date: Re: Problem with double byte
- Next by Date: Re: Problem with double byte
- Previous by thread: Re: Problem with double byte
- Next by thread: Re: Problem with double byte
- Index(es):