Solved

JNI - Problem with perfcounters.h

Posted on 2006-06-15
2
640 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now