i have dll with extern C method:
extern "C" {
int ADAPTERSHARED_EXPORT full_hash(unsigned char* data,
uint64_t size,
int algorithm,
char* result,
int *res_size
);
}
from java a call this method interface
public interface CA extends Library {
CA INSTANCE = (CA) Native.loadLibrary(
(Platform.isWindows() ? "HashAdapterC" : "libHAL"), CA.class);
int full_hash(byte[] data, long size, int algorithm, String result, IntByReference res_size);
}
and main method
public static void main(String[] args) {
logger.debug("being started");
try {
CA lib = CA.INSTANCE;
String str = "1234567";
String res = "";
IntByReference in = new IntByReference(32);
byte[] data = str.getBytes();
int i = lib.full_hash(data, str.length(), 3, res, in);
logger.debug("result = " + res);
logger.debug("error = " + i);
return;
} catch (Exception e) {
e.printStackTrace();
logger.error("err");
return;
}
}
after calling the result of an empty string.
and if call it from C
unsigned char data[] = {
0xB1, 0x94, 0xBA, 0xC8, 0x0A, 0x08, 0xF5, 0x3B,
0x36, 0x6D, 0x00, 0x8E, 0x58
};
uint64_t size = sizeof(data);
int res_size = 32;
char* result = (char*)malloc(res_size);
int is_success = hash(data, size, 3, result, &res_size);
if (is_success == 0)
{
printf("Success\n");
int i;
for (i = 0; i < res_size; ++i)
{
printf("%X", (unsigned char)result[i]);
}
printf("\n");
}
i get result string.
is't char* - String? or will I use a different type?
it was necessary to declare the result as byte[]
public interface CA extends Library {
CA INSTANCE = (CA) Native.loadLibrary(
(Platform.isWindows() ? "HashAdapterC" : "libHAL"), CA.class);
int full_hash(byte[] data, long size, int algorithm, byte[] result, IntByReference res_size);
}