![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
|
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
|
| 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! |