{
if (english)
objectName = translate(objectName);
Bag bag = new HashBag();
int pdhStatus = Pdhdll.ERROR_SUCCESS;
Memory szCounterListBuffer = null;
IntByReference dwCounterListSize = new IntByReference();
Memory szInstanceListBuffer = null;
IntByReference dwInstanceListSize = new IntByReference();
String szThisInstance = null;
// Determine the required buffer size for the data.
pdhStatus = Pdhdll.INSTANCE.PdhEnumObjectItemsA(null, // real time
// source
null, // local machine
objectName, // object to enumerate
szCounterListBuffer, // pass NULL and 0
dwCounterListSize, // to get length required
szInstanceListBuffer, // buffer size
dwInstanceListSize, //
Pdhdll.PERF_DETAIL_WIZARD, // counter detail level
0);
if (pdhStatus == Pdhdll.PDH_MORE_DATA)
{
// Allocate the buffers and try the call again.
szCounterListBuffer = new Memory(dwCounterListSize.getValue() * 4);
szInstanceListBuffer = new Memory((dwInstanceListSize.getValue() * 4));
if ((szCounterListBuffer != null) && (szInstanceListBuffer != null))
{
pdhStatus = Pdhdll.INSTANCE.PdhEnumObjectItemsA(null, // real
// time
// source
null, // local machine
objectName, // object to enumerate
szCounterListBuffer, // buffer to receive counter
// list
dwCounterListSize, szInstanceListBuffer, // buffer to
// receive
// instance
// list
dwInstanceListSize, Pdhdll.PERF_DETAIL_WIZARD, // counter
// detail
// level
0);
if (pdhStatus == Pdhdll.ERROR_SUCCESS)
{
// System.out.println ("Enumerating 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.
int i = 0;
for (szThisInstance = szInstanceListBuffer.getString(0); szThisInstance != null && szThisInstance.length() > 0; i += szThisInstance
.length() + 1, szThisInstance = szInstanceListBuffer.getString(i))
{
// System.out.println( szThisInstance);
bag.add(szThisInstance);
}