Skip to main content

Problems with JNA

3 replies [Last post]
komyg
Offline
Joined: 2009-05-13

Hi, I am new to the jna and I have the following method to define on the Java Interface that instantiates my dll and contains its methods:

<br />
DRV_EXPORT LumiStatus STDCALL LumiQueryNumberDevices(uint &nNumDevices,  char* const strIPList);<br />

First of all the jna specification states that in case of unsigned types I should use the java type correspondent to the native signed type and pass its value as a two's complement of the original value, therefore the first paramenter on the function above would be an int on java. Is this correct?

If for example I wanted to pass 3 as an argument for the first parameter, should I pass 1 (3 = 11 -> inverted = 00, 00 + 1 = 01 = 1) or 4294967293 (11 inverted considering 32 bits = 11111111111111111111111111111100 + 1 = 11111111111111111111111111111101 = 4294967293)?

Also this function returns the typedef enum below:

<br />
typedef enum tagLUMI_ERROR<br />
{<br />
	LUMI_STATUS_OK					= 0,			/* Operation completed successfully */<br />
	LUMI_STATUS_ERROR_DEVICE_OPEN			= 0x0001,		/* Could not find or open requested<br />
																biometric reader */<br />
	LUMI_STATUS_ERROR_DEVICE_CLOSE			= 0x0002,		/* Could not close biometric reader<br />
																or release allocated resources */<br />
	LUMI_STATUS_ERROR_CMD_NOT_SUPPORTED		= 0x0004,		/* This command is not supported on<br />
																current platform */<br />
	LUMI_STATUS_ERROR_COMM_LINK			= 0x0008,		/* General internal communication problem<br />
																prevented execution of command */<br />
	LUMI_STATUS_ERROR_PREPROCESSOR			= 0x0010,		/* Minimum thresholds for processing<br />
																quality were not achieved */<br />
	LUMI_STATUS_ERROR_CALIBRATION			= 0x0020,		/* Calibration cycle failed due to<br />
																inoperable hardware state */<br />
	LUMI_STATUS_ERROR_BUSY				= 0x0040,		/* Device is busy processing previous<br />
																command */<br />
	LUMI_STATUS_ERROR_INVALID_PARAMETER		= 0x0080,		/* Parameter or input is out of range */<br />
	LUMI_STATUS_ERROR_TIMEOUT			= 0x0100,		/* Event did not occur within programmed<br />
																time interval */<br />
	LUMI_STATUS_ERROR_INVALID_TEMPLATE		= 0x0200,		/* Supplied input template is invalid */<br />
	LUMI_STATUS_ERROR_MEMORY_ALLOCATION		= 0x0400,		/* Unable to allocate memory */<br />
	LUMI_STATUS_ERROR_INVALID_DEVICE_ID		= 0x0800,		/* Invalid connection handle */<br />
	LUMI_STATUS_ERROR_INVALID_CONNECTION_ID		= 0x1000,		/* Invalid instance ID */<br />
	LUMI_STATUS_ERROR_CONFIG_UNSUPPORTED    	= 0x2000,		/* Current configuration or policy does not<br />
																support the function that was just called */<br />
	LUMI_STATUS_UNSUPPORTED				= 0x4000,		/* The function is not currently supported by the SDK*/<br />
	LUMI_STATUS_INTERNAL_ERROR			= 0x8000,		/* An internal error occurred */<br />
	LUMI_STATUS_INVALID_PARAMETER			= 0x8001,		/* Invalid parameter or non allocated buffer passed to function*/<br />
	LUMI_STATUS_DEVICE_TIMEOUT			= 0x8002,		/* Biometric sensor is accessed by another process */<br />
	LUMI_STATUS_INVALID_OPTION			= 0x8004,		/* Invalid option, invalid argument, or invalid<br />
																argument size passed to function LumiSetOption*/<br />
	LUMI_STATUS_ERROR_MISSING_SPOOFTPL          	= 0x8008,       	/* Missing Spoof template from Composite image or ANSI<br />
																378 Template */<br />
	LUMI_STATUS_CANCELLED_BY_USER		       	= 0x8010,		/* If the LumiPresenceDetectCallback returns -2, then<br />
																the SDK will return this status code during capture*/<br />
	LUMI_STATUS_INVALID_FOLDER			= 0x8020,		/* Function LumiSetDCOptions returns this code if the folder<br />
																doesn't exist */<br />
	LUMI_STATUS_DC_OPTIONS_NOT_SET			= 0x8040,		/* Function LumiSaveLastCapture returns this code if the<br />
																(Data Collection) option was not set OR set to a non<br />
																existing folder */<br />
} LumiStatus;<br />

What is the equivalent of this enum in java?

Should I create a enum with the same members and values as above, or perhaps a class that extends enum and has variables with the same name and value as above?

Please help me.

Thanks,
Komyg

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fconrotte
Offline
Joined: 2009-05-30

According to the JNA mailing list, Native-side C enum are integer values. Java-side, they are enum objects. You have to tell JNA how to translate to the native value,
either with a TypeMapper or by making the enum objects implement NativeMapped.

peter__lawrey
Offline
Joined: 2005-11-01

In C, an enum is a way of managing aliases for numbers, but fundamentally they are all int values.
In Java, an enum is a group of objects (you cannot set the ordinal value of the enums, but can associate a value with each enum value)

AFAIK, the simplest thing to do is to treat the enum as an int value. You can then have a Map or Map if you like.

komyg
Offline
Joined: 2009-05-13

I've done a lot of search through the web on this subject lately and now it seems that maybe I might be better off using a helper program that I made sometime ago, that encapsulated some of the functions of this dll and made them simpler to use. Therefore instead of using functions that return the LumiStatus enum I would be using functions that return more common types like int or uchar*.

The thing is that those functions are inside a C++ class (code below). Is there a way to use jna with this class, or is it better if I just put those methods outside of the class and use them as standard C functions?

[code]
#ifndef LUMIDIGMHELPER_H
#define LUMIDIGMHELPER_H

#include "stdafx.h"
#include "LumiAPI.h"
#include "LumidigmException.h"
#include

using namespace std;
using namespace System::Runtime::InteropServices;

namespace ItautecLumidigmHelper
{
class LumidigmHelper
{
public:

// Struct que contém os dados das imagens capturadas pelo Lumidigm.
struct LumidigmImageData
{
uint imageWidth; // Largura da imagem
uint imageHeight; // Altura da imagem
uint imageBPP; // Bits per pixel da imagem
uint imageDPI; // DPI da imagem
};

// Essa função verifica quantos dispositivos estão conectados com o
// computador no qual ela está sendo executada.
//
// @return O número de dispositivos da forma uint.
static uint getNumConnectedDevices()
{
LumiStatus status;
uint numDevices;

status = LumiQueryNumberDevices(numDevices, "192.168.0.65");

if (status != LUMI_STATUS_OK)
throw LumidigmException(status);

return numDevices;
}

// Construtor
// OBS: Esse construtor assume que o dispositivo a ser inicializado é o de
// número 0.
LumidigmHelper();

// Construtor
//
// @param uint DeviceNumber Número do dispositivo a ser inicializado.
LumidigmHelper(uint deviceNumber);

// Captura a imagem do dedo do usuário e gera um novo template.
//
// @return o novo template gerado.
uchar* generateTemplate();

// Captura a imagem do dedo do usuário e realiza um match entre o template
// gerado a partir do dedo do usuário e o template fornecido.
//
// @param uchar* fingerTemplate Template a ser comparado.
//
// @return score da comparação entre os dois templates.
uint verify(uchar* fingerTemplate, uint templateSize);

// Captura uma imagem com o Lumidigm.
//
// @return string de dados que representa a imagem capturada.
uchar* capturaImagem();

// Retorna dados sobre as imagens capturadas, como altura, largura, etc.
//
// @return Struct do tipo LumidigmImage com os dados sobre as
// imagens capturadas.
LumidigmImageData getImgData();

// Destructor
//
// Fecha a conexão com o Lumidgm.
~LumidigmHelper();

private:

LUMI_DEVICE device;
LUMI_HANDLE deviceHandle;

LumidigmImageData imgData;
};
}

#endif
[/code]

Thanks,
Komyg