{
if (_indexes != null)
return;
_indexes = new HashMap();
int ret = 0;
IntByReference hkey = new IntByReference();
ret = Advapi32.INSTANCE.RegOpenKeyExA(Advapi32.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib\\009", 0,
Advapi32.KEY_READ, hkey);
// System.out.println(">> "+ret + " " +
// Integer.toHexString(hkey.getValue()));
int BufferSize = 1;
int BYTEINCREMENT = 1024;
Memory PerfData = new Memory(BufferSize);
PerfData.clear();
IntByReference PBufferSize = new IntByReference();
PBufferSize.setValue(BufferSize);
// System.out.println("Allocating memory...");
for (ret = Advapi32.INSTANCE.RegQueryValueExA(hkey.getValue(), "Counter", null, null, PerfData, PBufferSize); ret == Advapi32.ERROR_MORE_DATA; ret = Advapi32.INSTANCE
.RegQueryValueExA(hkey.getValue(), "Counter", null, null, PerfData, PBufferSize))
{
// Get a buffer that is big enough.
BufferSize += BYTEINCREMENT;
PBufferSize = new IntByReference();
PBufferSize.setValue(BufferSize);
PerfData = new Memory(BufferSize);
PerfData.clear();
}
// System.out.println("Final buffer size is " +PBufferSize.getValue());
if (ret != Pdhdll.ERROR_SUCCESS)
System.out.println(Integer.toHexString(ret));
else
{
String key;
String counter;
int i = 0;
while (i < PBufferSize.getValue())
{
key = PerfData.getString(i);
i += key.length() + 1;
counter = PerfData.getString(i);
i += counter.length() + 1;