Solved

JNI - Problem with perfcounters.h

Posted on 2006-06-15
2
642 Views
Last Modified: 2007-12-19
Following on from here:
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21790438.html

Hi Experts,
My question is:
1)  how can I build a shared library (dll file) with my "JNI" cpp file?
( I have tried many ways to build the dll file (with VS C++, gcc from MinWG, or cynwin))

My cpp file is:

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "CpuUsage.h"
#include "SysUsage_SystemInfo.h"



/*
 * Class:    SysUsage_SystemInfo
 * Method:    getProcessCPUPercentage
 * Signature: ()I
 */
 CCpuUsage mCpuUsage;
 struct helper
 {

  helper() {mCpuUsage.GetCpuUsage() ; } // first call
  };

JNIEXPORT jint JNICALL Java_SysUsage_SystemInfo_getProcessCPUPercentage
  (JNIEnv *, jclass)
  {
       jint SysCpuUsage = mCpuUsage.GetCpuUsage();
       return SysCpuUsage;
  }

/*
 * Class:     SysUsage_SystemInfo
 * Method:    getMaxMem
 * Signature: ()J
 */
JNIEXPORT jlong JNICALL Java_SysUsage_SystemInfo_getMaxMem
  (JNIEnv *, jclass)
  {
       jlong reVal = 0;
       return reVal;
  }

/*
 * Class:     SysUsage_SystemInfo
 * Method:    getFreeMem
 * Signature: ()J
 */
JNIEXPORT jlong JNICALL Java_SysUsage_SystemInfo_getFreeMem
  (JNIEnv *, jclass)
  {
       jlong reVal = 0;
       return reVal;
  }

ERROR: 59 errors but similar to the followings: (all about the perfcounters.h)
c:\eclipseworkspace\rmutils\cppsrc\perfcounters.h(20) : error C2061: syntax error : identifier 'PERF_DATA_BLOCK'
        c:\eclipseworkspace\rmutils\cppsrc\perfcounters.h(334) : see reference to class template instantiation             CPerfCounters<T>' being compiled

c:\eclipseworkspace\rmutils\cppsrc\perfcounters.h(222) : error C2535: '__int64 __thiscall CPerfCounters<__int64>::GetCounterValueForProcessID(void)' : member function already defined or declared
        c:\eclipseworkspace\rmutils\cppsrc\perfcounters.h(46) : see declaration of 'GetCounterValueForProcessID'

Thanks
0
Comment
Question by:phongtran72
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 16916195
You'll need to

#include <winperf.h> // has the declaration of 'PERF_DATA_BLOCK'

before including your 'perfcounters.h'
0
 

Author Comment

by:phongtran72
ID: 16919367
Hi JKR,
Thanks for your response. It works!

However I cannot build the shared DLL file. Could you (or someone, please) give me instruction how to build DLL using
Visual Studio 2005, PLEASE? (I have not used this IDE for years because I am mainly developing Java applications.)

Thanks in advance.

0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question