Windows Vista Forums
Vista Forums Home Join Vista Forums Tech Publications Windows 7 Forum Vista Tutorials Webcasts Tags

Welcome to Vista Forums we are your forum for Windows Vista help and discussion. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Vista Newsgroups > Vista security

PDH library can not be accessed through Vista 64 bit .

Update your Vista Drivers
Reply
 
Thread Tools Display Modes
Old 04-16-2007   #1 (permalink)
bhadra
Guest


 

PDH library can not be accessed through Vista 64 bit .

Hi ,

I was trying to get processor related information through PDH
library . This works well on all platform but in Vista 64 bit , I have
some problem .
Here is my code :
===============
Sample.java
===============
class Sample
{
//Declaring native method
public native int queryCPU ();
static
{
//loading the myLibrary DLL
System.loadLibrary("CPULoad");
}
}
================
SampleApp.java
================
class SampleApp
{
public static void main(String args[])
{
System.out.println("Calling main method of main");
int result = new Sample().queryCPU();

}
}

=============
Compile the two files
===============
javac *.java

==================
Create .h file for CPP Application
==================
javah -jni Sample

This creates a Sample.h file

==================
Create a DLL called CPULoad.dll with this following .c file
==============
#include <jni.h>
#include "sample.h"
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <tchar.h>
#include <pdh.h>
#include <pdhmsg.h>


JNIEXPORT jint JNICALL
Java_Sample_queryCPU (JNIEnv *env, jobject obj)
{
printf ("Native method implementation!\n");
while (1)
{
PDH_STATUS status;
HQUERY perfQuery = NULL;
HCOUNTER uptimeCounter;
//char uptimeCounterPath[] = "\\\\.\\System\\System Up Time";
//char uptimeCounterPath[] = "\\Memory\\Pages/sec";
char uptimeCounterPath[] = "\\Processor(_Total)\\% Processor
Time";
PDH_FMT_COUNTERVALUE uptimeValue;
//.......................
int seconds = 0;
//
// Create a PDH query
//
if( PdhOpenQuery(NULL, 0, &perfQuery ) != ERROR_SUCCESS )
{
printf ("PdhOpenQuery failed");
return FALSE;
}

if (perfQuery == NULL)
{
printf ("perfQuery failed");
return FALSE;
}
//
// Associate the uptime counter with the query
//
status = PdhAddCounter(perfQuery, uptimeCounterPath,
0, &uptimeCounter );
if( status != ERROR_SUCCESS )
{
printf ("PdhAddCounter failed");
return FALSE;
}


status = PdhCollectQueryData( perfQuery );
if( status != ERROR_SUCCESS )
{
printf ("PdhCollectQueryData123 failed");
return FALSE;
}

Sleep(2000);
status = PdhCollectQueryData( perfQuery );
if( status != ERROR_SUCCESS )
{
printf ("PdhCollectQueryData123 failed");
return FALSE;
}

//
// Get the formatted counter value
//

status = PdhGetFormattedCounterValue( uptimeCounter,
PDH_FMT_LARGE , NULL, &uptimeValue );
if( status != ERROR_SUCCESS )
{
printf ("PdhGetFormattedCounterValue failed");
return FALSE;
}
//
// Close the query
//
PdhCloseQuery( &perfQuery );

seconds = (DWORD) (uptimeValue.largeValue);
printf ("System Up time =%d\n",uptimeValue.longValue);
Sleep(15);

}
return 1;
}

================================
Note that to link this file you need to put pdh.lib in the path . I
build it on Visual Studio 6 SP5 .

Now copy CPUload.dll , Sample.class and SampleApp.class in some
directory say C:\temp.

Run this on XP , 2003 etc etc
java SampleApp
This will produce an oulput like this :
====================================
Calling main method of main
Native method implementation!
System Up time =63
System Up time =22
System Up time =46
System Up time =30
System Up time =33
System Up time =67
System Up time =16
System Up time =28
System Up time =40
System Up time =3
System Up time =69
System Up time =17
=========================================

Now logon to Vista 64 bit box as an user who has administrative
priviledges .

Create a temp directory .
Put the above 3 files under the temp directory .
and run java SampleApp

This will produce the follwoing output :
=============================
Calling main method of main
Native method implementation!
PdhCollectQueryData123 failed
================================

I tried to build with the dll with mt.exe that comes with VC 8
my manifest file looks like this :
=======================
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator"></
requestedExecutionLevel>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
==========================

and then I linked it like this :
mt.exe -manifest CPUload.dll.manifest -outputresource:CPUload.dll;2

Still I am getting the same output .

Let me know on how could I troubleshoot this ?

Thanks,
Abhijit


My System SpecsSystem Spec
Reply
Update your Vista Drivers

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Vista remember the last folder accessed? HeneryHawk Vista General 0 04-22-2008 01:21 AM
After Vista upgrade, 2nd HD can't be accessed Ben Vista hardware & devices 4 03-31-2008 04:22 PM
"Windows Installer Service could not be accessed in Vista rynner Vista General 5 01-08-2008 11:48 PM
WMP11 - can no longer find library or add to library axel000 Vista music pictures video 4 10-18-2007 10:33 PM
Windows Vista installer service cannot be accessed karein_rask@yahoo.com Vista General 0 08-05-2007 11:32 AM


Complimentary Industry Resources

Vista Forums has joined forces with TradePub.com to offer you a new, exciting, and entirely free professional resource. Visit http://vistax64.tradepub.com today to browse our selection of complimentary Industry magazines, white papers, webinars, podcasts, and more across 34 industry sectors. No credit cards, coupons, or promo codes required. Try it today!




Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51