0 0

JNA调用Dll文件问题5

下面是c++的代码:
// DllTest.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "iostream"
#include "stdafx.h"
#define _WIN32_WINNT   0x0501
#include <Windows.h>
#define MYLIBAPI  extern   "C"     __declspec( dllexport ) 

struct Point{
	int x;
	int y;
};

/*
要返回的函数
*/
MYLIBAPI void say(wchar_t* pValue);
MYLIBAPI int add(int a,int b);
MYLIBAPI double* getCpuInfo(int wait);
MYLIBAPI double* getArray();
MYLIBAPI int* getIntArray();
MYLIBAPI Point getPoint();


/*
函数的定义
*/
Point getPoint(){
	Point p;
	p.x=15;
	p.y=49;
	return p;
}

__int64 CompareFileTime ( FILETIME time1, FILETIME time2 )
{
	__int64 a = time1.dwHighDateTime << 32 | time1.dwLowDateTime ;
	__int64 b = time2.dwHighDateTime << 32 | time2.dwLowDateTime ;

	return   (b - a);
}

void  say(wchar_t* pValue){
	
	std::wcout.imbue(std::locale("chs"));
	std::wcout<<L"say::"<<pValue<<std::endl;
}
int add(int a,int b){
	return a+b;
}
double* getArray(){
	double arr[2] = {10.2,53.636};
	return arr;
}

int* getIntArray(){
	int* p;
	int arr[2] = {3,53};
	p = arr;
	return p;
}

double* getCpuInfo(int wait){
	HANDLE hEvent;
	BOOL res ;

	FILETIME preidleTime;
	FILETIME prekernelTime;
	FILETIME preuserTime;

	FILETIME idleTime;
	FILETIME kernelTime;
	FILETIME userTime;

	res = GetSystemTimes( &idleTime, &kernelTime, &userTime );


	preidleTime = idleTime;
	prekernelTime = kernelTime;
	preuserTime = userTime ;

	hEvent = CreateEvent (NULL,FALSE,FALSE,NULL); // 初始值为 nonsignaled ,并且每次触发后自动设置为nonsignaled

	WaitForSingleObject( hEvent,wait); //等待500毫秒
	res = GetSystemTimes( &idleTime, &kernelTime, &userTime );
	int idle = CompareFileTime( preidleTime,idleTime);
	int kernel = CompareFileTime( prekernelTime, kernelTime);
	int user = CompareFileTime(preuserTime, userTime);
	double cpu = (kernel +user - idle) *100.0/(kernel+user);
	double cpuidle = ( idle) *100.0/(kernel+user);

	//cout <<cpu<<endl;
	//cout <<cpuidle<<endl;
	double d[2] ={cpu,cpuidle}; 
	return d;
}







请问对应的java的jna代码怎么定义?
2012年1月09日 18:32
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics