Function mapping Delphi DLL with Java (JNA) - java

I'm having problems when trying to use two functions of a DLL in Delphi with the JNA Java. In Test Software (Delphi, provided with DLL by ), I have this functions (working perfectly in test software):
function abrir_conexao (const modelo : **byte**; const host : **pansichar**; const porta : **word**; const senha : **pansichar**) : integer; stdcall external 'comunicacao.dll';
function enviar_comando (const comando : **byte**; var tamanho : **byte**; var dados : **pbyte**) : integer; stdcall external 'comunicacao.dll';
I'm trying to implement these functions in Java (JNA). I'm getting usually load the dll , however , I believe that the problem lies in the use of correct primitive variables:
public int abrir_conexao (**byte** modelo, **String** host, **short** porta, **String** senha);
public int enviar_comando(**byte** comando, **byte** tamanho, **byte[]** dados);
But it's not working. Can anyone help ?

For the following native functions:
function abrir_conexao (const modelo : byte; const host : pansichar; const porta : word; const senha : pansichar) : integer; stdcall external 'comunicacao.dll';
function enviar_comando (const comando : byte; var tamanho : byte; var dados : pbyte) : integer; stdcall external 'comunicacao.dll';
JNA mapping:
public interface MyLibrary extends StdCallLibrary {
MyLibrary INSTANCE = (MyLibrary)Native.loadLibrary('comunicacao', MyLibrary.class);
int abrir_conexo(byte modelo, String host, short port, String senha);
int enviar_comando(byte comando, byte tamanho, byte[] dados);
}

Related

SIGABRT error when returning from C++ code from java module in android

Still new to android and java but learning more each day :)
This question refers to
Ok, the error refers to
expression failed to parse:
error: <user expression 27>:1:1: 'bl' has unknown type; cast it to its declared type to use it
bl
^~
and
expression failed to parse:
error: <user expression 28>:1:1: 'uxtb' has unknown type; cast it to its declared type to use it
uxtb.w
^~~~
I call (will want a short ) result = getCheckSum(A, B); from my java code.
The method in my C++ code is
//---------------------------------------------------------------------------
unsigned short ekmCheckCRC16(const unsigned char *dat, unsigned short len)
{
unsigned short crc = 0xffff;
while (len--)
{
crc = (crc >> 8 ) ^ ekmCrcLut[(crc ^ *dat++) & 0xff];
}
crc = (crc << 8 ) | (crc >> 8);
crc &= 0x7f7f;
return crc;
}
//---------------------------------------------------------------------------
// Implementation of the native method getCheckSum()
extern "C"
JNIEXPORT unsigned short JNICALL
Java_com_(...)_getCheckSum(JNIEnv *env, jobject thiz, jstring a) {
const char * aCStr = env->GetStringUTFChars(a, NULL);
if(NULL == aCStr)
return NULL;
unsigned short crc = ekmCheckCRC16(reinterpret_cast<const unsigned char *>(aCStr), strlen(aCStr));
return crc;
}
This code is experimental showing the actual code I want to run ekmCheckCRC16( ... ), its purpose is to learn how to return a value back to the java module.
The error message seems to be clear 'unknown' type cast, so question is, how should I be returning the value of aCStr?
Thanks in advance.
Solved my problem, was simple error of not changing one important detail before executing call i was looking for a return type of short but had String in native declaration.
I had
private native String getCheckSum(String a);
it should have been
`private native short getCheckSum(String a);`
My call was / is
short result = getCheckSum(A);
Worked fine after correcting my mistake.
for those interested my c++ code
#include <jni.h> // JNI header provided by JDK
#include "ekmCheckSum.h"
#include <iostream> // C++ standard IO header
using namespace std;
//---------------------------------------------------------------------------
void ekmCheckSum() {
}
static const unsigned short ekmCrcLut[256] = {
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040
};
//---------------------------------------------------------------------------
unsigned short ekmCheckCRC16(const unsigned char *dat, unsigned short len)
{
unsigned short crc = 0xffff;
while (len--)
{
crc = (crc >> 8 ) ^ ekmCrcLut[(crc ^ *dat++) & 0xff];
}
crc = (crc << 8 ) | (crc >> 8);
crc &= 0x7f7f;
return crc;
}
//---------------------------------------------------------------------------
// Implementation of the native method getCheckSum()
extern "C"
JNIEXPORT unsigned short JNICALL
Java_com_[project name]_ekmV4Fields_getCheckSum(JNIEnv *env, jobject thiz, jstring a) {
const char * aCStr = env->GetStringUTFChars(a, NULL);
if(NULL == aCStr)
return NULL;
unsigned short crc = ekmCheckCRC16(reinterpret_cast<const unsigned char *>(aCStr), strlen(aCStr));
return crc;
}
my .h file contains
#ifndef PROJECT_NAME_EKMCHECKSUM_H
#define PROJECT_NAME_EKMCHECKSUM_H
class ekmCheckSum
{
private:
public:
ekmCheckSum();
unsigned short ekmCheckCRC16(const unsigned char *dat, unsigned short len);
};
#endif //PROJECT_NAME_EKMCHECKSUM_H
my java file includes
static {System.loadLibrary("ekmCheckSum");}
private native short getCheckSum(String a);
public void SetEkmFieldValueStrings(String A, String B)
{
/* if length of A is less than 250 chars, read is no good, discard
* NOTE: both Strings A and B will need to be validated for checksum
* TODO check A & B if checksum is correct
* */
boolean _aOk = false, _bOk=false;
short result = getCheckSum(A);
...
...

Java JNI run class from module [duplicate]

I created a C++ class that is supposed to call Main.main by following: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html#wp9502.
I didn't get it to work so I followed: http://www.coderanch.com/t/525082/CPP/create-JVM-native-code-call
and :
imp_JNI_Crea">http://www.codeproject.com/Questions/263687/Linker-error-undefined-reference-to-imp_JNI_Crea
None of which worked. So I changed my code back to what the Invocation API article by oracle says (the first link).
My C++ code looks like:
In JNI.hpp file:
#include <jni.h>
#include <windows.h>
#include <iostream>
class Jvm
{
private:
JavaVM* jvm;
JNIEnv* env;
JavaVMInitArgs jvm_args;
JavaVMOption* options;
public:
Jvm();
};
In JNI.cpp file:
Jvm::Jvm()
{
options = new JavaVMOption[3];
options[0].optionString = "-Djava.compiler=NONE";
options[1].optionString = "-Djava.class.path=C:/Users/Brandon/Documents/NetBeansProjects/Loader/build/classes";
options[2].optionString = "-verbose:class";
jvm_args.version = JNI_VERSION_1_6;
jvm_args.nOptions = 3;
jvm_args.options = options;
jvm_args.ignoreUnrecognized = false;
//JNI_GetDefaultJavaVMInitArgs(&jvm_args);
JNI_CreateJavaVM(&jvm, reinterpret_cast<void**>(&env), &jvm_args);
jclass MainClass = env->FindClass("loader.Main");
//Crashes on the next line:
jmethodID MainMethod = env->GetStaticMethodID(MainClass, "main", "([Ljava/lang/String;)V");
MessageBox(NULL, "", "", 0);
Sleep(1000);
jvm->DestroyJavaVM();
delete[] options;
}
My java code looks like:
package loader;
public class Main {
public static void main(String[] args) {
//JavaProcess.exec(ClientApplet.class);
System.out.println("Hello!");
}
}
And the verbose prints:
[Loaded loader.Main from file:/C:/Users/Brandon/Documents/NetBeansProjects/Loader/build/classes/]
Process returned -1073741571 (0xC00000FD) execution time : 1.730 s
Press any key to continue.
What am I doing wrong? Why does it fail to call the method?
The JNI.dll that I loaded is from: C:\Program Files\Java\jdk1.7.0_21\jre\bin\server\jvm.dll because the latest Java 7u25 doesn't have a bin\client\jvm.dll.
I even statically linked to the jvm.lib: C:\Program Files\Java\jdk1.7.0_21\lib\jvm.lib.
jclass MainClass = env->FindClass("loader.Main");
This is wrong. You have to use slashes instead of dots when using JNI functions, just like in method signatures.
The correct code is:
jclass MainClass = env->FindClass("loader/Main");

fetching windows current user with java native interfaces

I am trying to make a proof of concept where in a cpp program I fetch the windows username and then call this program from a java code, using Java native interface(JNI). Now what i have so far is, a sample JNI hello world program which is able to compile and print Hello world or what what ever parameter I set up. Now in a separate cpp snippet i am able to fetch the current username and it works as well; looks as follows:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
char acUserName[100];
DWORD nUserName = sizeof(acUserName);
if (GetUserName(acUserName, &nUserName)) {
cout << "User name is " << acUserName << "." << endl;
cin.get();
}
return 0;
}
When compiled and executed using my G++ in command prompt it prints the current username correctly.
Now i just want to combine the two programs. When I do that as follows
public class Sample1
{
public native String fetchCurrentUserName();
public static void main(String[] args)
{
System.loadLibrary("Sample1");
Sample1 sample = new Sample1();
String userName = sample.fetchCurrentUserName();
System.out.println("userName: " + userName);
}
}
This is the java part and the cpp part is as follows:
#include "Sample1.h"
#include <string.h>
#include <iostream>
#include <windows.h>
using namespace std;
JNIEXPORT jstring JNICALL Java_Sample1_fetchCurrentUserName
(JNIEnv *env, jobject obj) {
char acUserName[100];
DWORD nUserName = sizeof(acUserName);
if (GetUserName(acUserName, &nUserName)) {
cout << "User name is " << acUserName << "." << endl;
cin.get();
}
const char* userName = acUserName;
//const char* userName = "acUserName";
return env->NewStringUTF(userName);
}
void main(){}
This does not compile anymore, it says
Sample1.obj : error LNK2019: unresolved external symbol __imp_GetUserNameA referenced in function Java_Sample1_fetchCurrentUserName
Sample1.dll : fatal error LNK1120: 1 unresolved externals
I used the following command to compile the JNI code.
cl -I"C:\Program Files\Java\jdk1.8.0_131\include" -I"C:\Program Files\Java\jdk1.8.0_131\include\win32" -LD Sample1.cpp -FeSample1.dll
as per tutorial from https://www.ibm.com/developerworks/java/tutorials/j-jni/j-jni.html. Now from few other questions in stack overflow it seems somehow my program is unable to link the windows library or leader somehow. But I have no clue as to how this can be solved. Any body have any bright ideas? Please make my day! Thank you for your time :D I looked into Linking of dll file in JNI which is very relevant for my question. But not sure if the solutions are applicable to me.
Edit
error: LNK1120: 5 unresolved externals This question had similar problem and it seems to have same solution which is as suggested by Remy to link with Advapi32.lib. At least now i learned few new things like #pragma comments and the role of Advapi32 library. Many thanks!
Your code compiles fine. You are actually getting a linker error, not a compiler error.
From the error message, you can see that your C++ code is trying to call a GetUserNameA() function. GetUserName() is a preprocessor #define macro in winbase.h (which is included by windows.h) that resolves to GetUserNameA() when UNICODE is not defined:
WINADVAPI
BOOL
WINAPI
GetUserNameA (
__out_ecount_part_opt(*pcbBuffer, *pcbBuffer) LPSTR lpBuffer,
__inout LPDWORD pcbBuffer
);
WINADVAPI
BOOL
WINAPI
GetUserNameW (
__out_ecount_part_opt(*pcbBuffer, *pcbBuffer) LPWSTR lpBuffer,
__inout LPDWORD pcbBuffer
);
#ifdef UNICODE
#define GetUserName GetUserNameW
#else
#define GetUserName GetUserNameA // <-- HERE!
#endif // !UNICODE
As there is no GetUserNameA() function implemented in your C++ code, but there is at least a declaration available (from winbase.h), the compiler emits machine code that references GetUserNameA() externally (via a symbol named __imp_GetUserNameA). When the linker is then invoked after compiling is finished, the linker outputs the "unresolved" error because it is not able to find an implementation of any GetUserNameA function to satisfy that reference.
GetUserNameA() is a Win32 API function implemented in Advapi32.dll. You need to link to Advapi32.lib from your compiler's Windows SDK so the linker can find the implementation of GetUserNameA().
One way to do that is to add a #pragma comment(lib) statement to your C++ code, eg:
#include "Sample1.h"
#include <windows.h>
#include <iostream>
using namespace std;
#pragma comment(lib, "Advapi32.lib") // <-- add this!
JNIEXPORT jstring JNICALL Java_Sample1_fetchCurrentUserName(JNIEnv *env, jobject obj) {
char acUserName[100] = {};
DWORD nUserName = sizeof(acUserName);
if (GetUserNameA(acUserName, &nUserName)) {
cout << "User name is " << acUserName << "." << endl;
}
else {
DWORD dwErr = GetLastError();
cout << "Unable to get User name, error " << dwErr << "." << endl;
}
return env->NewStringUTF(acUserName);
}
void main() {}
Alternatively:
#include "Sample1.h"
#include <windows.h>
#include <iostream>
#include <vector>
using namespace std;
#pragma comment(lib, "Advapi32.lib")
JNIEXPORT jstring JNICALL Java_Sample1_fetchCurrentUserName(JNIEnv *env, jobject obj) {
DWORD nUserName = 100, dwErr;
std::vector<char> acUserName(nUserName);
do {
if (GetUserNameA(&acUserName[0], &nUserName)) {
cout << "User name is " << &acUserName[0] << "." << endl;
break;
}
dwErr = GetLastError();
if (dwErr != ERROR_INSUFFICIENT_BUFFER) {
cout << "Unable to get the User name, error " << dwErr << "." << endl;
break;
}
acUserName.resize(nUserName);
}
while (true);
return env->NewStringUTF(&acUserName[0]);
}
void main() {}
That being said, NewStringUTF() requires an input string in modified UTF-8 format. However, GetUserNameA() outputs ANSI format (hence the A in its name), not in UTF-8, let alone modified UTF-8. Windows has no concept of modified UTF-8 at all. Your code will work correctly only if the username does not contain any non-ASCII characters in it.
Your C++ code really should be calling GetUserNameW() instead, which outputs in UTF-16 format. Then you can use NewString() instead of NewStringUTF() (Java strings use UTF-16 anyway), eg:
#include "Sample1.h"
#include <windows.h>
#include <iostream>
using namespace std;
#pragma comment(lib, "Advapi32.lib")
JNIEXPORT jstring JNICALL Java_Sample1_fetchCurrentUserName(JNIEnv *env, jobject obj) {
WCHAR acUserName[100];
DWORD nUserName = 100;
if (GetUserNameW(acUserName, &nUserName)) {
--nUserName; // ignore the null terminator
wcout << L"User name is " << acUserName << L"." << endl;
}
else
{
nUserName = 0;
DWORD dwErr = GetLastError();
cout << "Unable to get the User name, error " << dwErr << "." << endl;
}
return env->NewString(reinterpret_cast<jchar*>(acUserName), nUserName);
}
void main() {}
Alternatively:
#include "Sample1.h"
#include <windows.h>
#include <iostream>
#include <vector>
using namespace std;
#pragma comment(lib, "Advapi32.lib")
JNIEXPORT jstring JNICALL Java_Sample1_fetchCurrentUserName(JNIEnv *env, jobject obj) {
DWORD nUserName = 100, dwErr;
std::vector<WCHAR> acUserName(nUserName);
do {
if (GetUserNameW(&acUserName[0], &nUserName)) {
--nUserName; // ignore the null terminator
wcout << L"User name is " << &acUserName[0] << L"." << endl;
break;
}
dwErr = GetLastError();
if (dwErr != ERROR_INSUFFICIENT_BUFFER) {
nUserName = 0;
cout << "Unable to get the User name, error " << dwErr << "." << endl;
break;
}
acUserName.resize(nUserName);
}
while (true);
return env->NewString(reinterpret_cast<jchar*>(&acUserName[0]), nUserName);
}
void main() {}

jna wrapping shared .so library - access class

I have an opensource shared library called libmbc.so. I am interested in using this library in a java implementation which should be able to reproduce a behavior already tested in c++. Ideally I aim to have access to a class in this library called MBCNodal, and call its member functions in the java wrapper.
If I unroll the content of the shared library with nm -gC libmbc.so, I obtain the following
U __assert_fail##GLIBC_2.2.5
U bind##GLIBC_2.2.5
000000000020e278 B __bss_start
U close##GLIBC_2.2.5
U connect##GLIBC_2.2.5
w __cxa_finalize##GLIBC_2.2.5
U __cxa_pure_virtual##CXXABI_1.3
U __cxa_rethrow##CXXABI_1.3
000000000020e278 D _edata
000000000020e280 B _end
U __errno_location##GLIBC_2.2.5
0000000000009ab0 T _fini
U fprintf##GLIBC_2.2.5
U freeaddrinfo##GLIBC_2.2.5
U free##GLIBC_2.2.5
U fwrite##GLIBC_2.2.5
U getaddrinfo##GLIBC_2.2.5
w __gmon_start__
U __gxx_personality_v0##CXXABI_1.3
0000000000003db8 T _init
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
w _Jv_RegisterClasses
U malloc##GLIBC_2.2.5
0000000000004670 T mbc_check_cmd
000000000020e27c B mbc_dummy
00000000000046c0 T mbc_get_cmd
0000000000004850 T mbc_inet_init
0000000000005f60 T mbc_modal_destroy
0000000000005690 T mbc_modal_get_motion
0000000000005a40 T mbc_modal_init
0000000000005b90 T mbc_modal_negotiate_request
0000000000005db0 T mbc_modal_negotiate_response
00000000000058d0 T mbc_modal_put_forces
00000000000055d0 T mbc_nodal_destroy
0000000000004970 T mbc_nodal_get_motion
0000000000004c30 T mbc_nodal_init
00000000000051d0 T mbc_nodal_negotiate_request
00000000000053f0 T mbc_nodal_negotiate_response
0000000000004b30 T mbc_nodal_put_forces
0000000000004720 T mbc_put_cmd
00000000000048f0 T mbc_unix_init
00000000000097a0 T mbdyn_host2inet_addr
0000000000009980 T mbdyn_make_inet_socket
0000000000009890 T mbdyn_make_inet_socket_type
0000000000009aa0 T mbdyn_make_named_socket
00000000000099a0 T mbdyn_make_named_socket_type
U recv##GLIBC_2.2.5
U send##GLIBC_2.2.5
U snprintf##GLIBC_2.2.5
U socket##GLIBC_2.2.5
U stderr##GLIBC_2.2.5
U stdout##GLIBC_2.2.5
U strerror##GLIBC_2.2.5
U strlen##GLIBC_2.2.5
U strncpy##GLIBC_2.2.5
U _Unwind_Resume##GCC_3.0
U usleep##GLIBC_2.2.5
U operator delete(void*, unsigned long)##CXXABI_1.3.9
0000000000006000 T MBCBase::SetTimeout(int)
0000000000006010 T MBCBase::SetVerbose(bool)
0000000000007710 T MBCBase::DynamicsLabel()
0000000000006020 T MBCBase::SetDataAndNext(bool)
0000000000007a20 T MBCBase::F(unsigned char)
0000000000007bf0 T MBCBase::M(unsigned char)
00000000000064b0 T MBCBase::Init(char const*)
0000000000006510 T MBCBase::Init(char const*, unsigned short)
00000000000062b0 T MBCBase::SetStatus(MBCBase::Status)
00000000000063e0 T MBCBase::MBCBase()
00000000000063e0 T MBCBase::MBCBase()
0000000000006490 T MBCBase::~MBCBase()
0000000000006400 T MBCBase::~MBCBase()
0000000000006400 T MBCBase::~MBCBase()
0000000000009310 T MBCModal::Initialize(MBCBase::Rot, unsigned int)
0000000000009490 T MBCModal::DynamicsLabel()
00000000000094b0 T MBCModal::F(unsigned char)
00000000000094d0 T MBCModal::M(unsigned char)
0000000000009730 T MBCModal::P(unsigned int)
00000000000093a0 T MBCModal::MBCModal(MBCBase::Rot, unsigned int)
00000000000092c0 T MBCModal::MBCModal()
00000000000093a0 T MBCModal::MBCModal(MBCBase::Rot, unsigned int)
00000000000092c0 T MBCModal::MBCModal()
0000000000006470 T MBCModal::~MBCModal()
0000000000006450 T MBCModal::~MBCModal()
0000000000006450 T MBCModal::~MBCModal()
0000000000007d40 T MBCNodal::Initialize(MBCBase::Rot, unsigned int, bool, MBCBase::Rot, bool)
0000000000008e60 T MBCNodal::DynamicsLabel(unsigned int)
0000000000007f20 T MBCNodal::DynamicsLabel()
0000000000007f40 T MBCNodal::F(unsigned char)
0000000000009110 T MBCNodal::F(unsigned int, unsigned char)
0000000000007f60 T MBCNodal::M(unsigned char)
0000000000009220 T MBCNodal::M(unsigned int, unsigned char)
0000000000007e00 T MBCNodal::MBCNodal(MBCBase::Rot, unsigned int, bool, MBCBase::Rot, bool)
0000000000007cf0 T MBCNodal::MBCNodal()
0000000000007e00 T MBCNodal::MBCNodal(MBCBase::Rot, unsigned int, bool, MBCBase::Rot, bool)
0000000000007cf0 T MBCNodal::MBCNodal()
0000000000006430 T MBCNodal::~MBCNodal()
0000000000006410 T MBCNodal::~MBCNodal()
0000000000006410 T MBCNodal::~MBCNodal()
00000000000077c0 T MBCBase::GetRefNodeF() const
0000000000007870 T MBCBase::GetRefNodeM() const
0000000000006780 T MBCBase::GetRefNodeR() const
00000000000066d0 T MBCBase::GetRefNodeX() const
0000000000006050 T MBCBase::bDataAndNext() const
0000000000006a20 T MBCBase::GetRefNodeXP() const
0000000000007660 T MBCBase::DynamicsLabel() const
0000000000006100 T MBCBase::GetRefNodeRot() const
0000000000006bb0 T MBCBase::GetRefNodeXPP() const
0000000000006150 T MBCBase::bAccelerations() const
0000000000006ad0 T MBCBase::GetRefNodeOmega() const
0000000000006860 T MBCBase::GetRefNodeTheta() const
0000000000006620 T MBCBase::KinematicsLabel() const
0000000000006c90 T MBCBase::GetRefNodeOmegaP() const
0000000000006940 T MBCBase::GetRefNodeEuler123() const
0000000000007950 T MBCBase::F(unsigned char) const
0000000000007af0 T MBCBase::M(unsigned char) const
0000000000006e60 T MBCBase::R(unsigned char, unsigned char) const
0000000000006d90 T MBCBase::X(unsigned char) const
00000000000075b0 T MBCBase::GetRefNodeDynamicsLabel() const
00000000000065a0 T MBCBase::GetRefNodeKinematicsLabel() const
00000000000071b0 T MBCBase::XP(unsigned char) const
0000000000007380 T MBCBase::XPP(unsigned char) const
0000000000007280 T MBCBase::Omega(unsigned char) const
0000000000006fb0 T MBCBase::Theta(unsigned char) const
0000000000006580 T MBCBase::GetCmd() const
0000000000006080 T MBCBase::GetRot() const
0000000000007480 T MBCBase::OmegaP(unsigned char) const
0000000000006190 T MBCBase::bLabels() const
00000000000060c0 T MBCBase::bRefNode() const
0000000000006030 T MBCBase::bVerbose() const
00000000000070b0 T MBCBase::Euler123(unsigned char) const
0000000000006070 T MBCBase::GetStatus() const
0000000000005fd0 T MBCModal::GetBasePtr() const
0000000000009480 T MBCModal::DynamicsLabel() const
0000000000005fe0 T MBCModal::GetRefNodePtr() const
00000000000093f0 T MBCModal::KinematicsLabel() const
00000000000094a0 T MBCModal::F(unsigned char) const
00000000000094c0 T MBCModal::M(unsigned char) const
00000000000096c0 T MBCModal::P(unsigned int) const
00000000000095a0 T MBCModal::Q(unsigned int) const
0000000000009410 T MBCModal::R(unsigned char, unsigned char) const
0000000000009400 T MBCModal::X(unsigned char) const
0000000000009600 T MBCModal::QP(unsigned int) const
0000000000009440 T MBCModal::XP(unsigned char) const
0000000000009460 T MBCModal::XPP(unsigned char) const
0000000000009670 T MBCModal::GetP() const
0000000000009520 T MBCModal::GetQ() const
00000000000063a0 T MBCModal::Close() const
0000000000009560 T MBCModal::GetQP() const
0000000000009450 T MBCModal::Omega(unsigned char) const
0000000000009420 T MBCModal::Theta(unsigned char) const
0000000000009470 T MBCModal::OmegaP(unsigned char) const
0000000000005ff0 T MBCModal::GetType() const
0000000000009430 T MBCModal::Euler123(unsigned char) const
00000000000094e0 T MBCModal::GetModes() const
0000000000006280 T MBCModal::GetMotion() const
0000000000006350 T MBCModal::Negotiate() const
0000000000006240 T MBCModal::PutForces(bool) const
0000000000005fa0 T MBCNodal::GetBasePtr() const
0000000000008af0 T MBCNodal::GetEuler123(unsigned int) const
0000000000008140 T MBCNodal::GetEuler123() const
0000000000008dd0 T MBCNodal::DynamicsLabel(unsigned int) const
0000000000007f10 T MBCNodal::DynamicsLabel() const
0000000000005fb0 T MBCNodal::GetRefNodePtr() const
0000000000008910 T MBCNodal::KinematicsLabel(unsigned int) const
0000000000007e80 T MBCNodal::KinematicsLabel() const
0000000000008d60 T MBCNodal::GetDynamicsLabel() const
0000000000008880 T MBCNodal::GetKinematicsLabel(unsigned int) const
0000000000007fb0 T MBCNodal::GetKinematicsLabel() const
0000000000007f30 T MBCNodal::F(unsigned char) const
00000000000090a0 T MBCNodal::F(unsigned int, unsigned char) const
0000000000007f50 T MBCNodal::M(unsigned char) const
0000000000009180 T MBCNodal::M(unsigned int, unsigned char) const
0000000000007ea0 T MBCNodal::R(unsigned char, unsigned char) const
00000000000083d0 T MBCNodal::R(unsigned int, unsigned char, unsigned char) const
0000000000007e90 T MBCNodal::X(unsigned char) const
0000000000008360 T MBCNodal::X(unsigned int, unsigned char) const
0000000000007ed0 T MBCNodal::XP(unsigned char) const
0000000000008600 T MBCNodal::XP(unsigned int, unsigned char) const
0000000000007ef0 T MBCNodal::XPP(unsigned char) const
0000000000008710 T MBCNodal::XPP(unsigned int, unsigned char) const
0000000000008fa0 T MBCNodal::GetF(unsigned int) const
0000000000008ef0 T MBCNodal::GetF() const
0000000000009010 T MBCNodal::GetM(unsigned int) const
0000000000008f30 T MBCNodal::GetM() const
00000000000089f0 T MBCNodal::GetR(unsigned int) const
0000000000008060 T MBCNodal::GetR() const
00000000000089a0 T MBCNodal::GetX(unsigned int) const
0000000000008020 T MBCNodal::GetX() const
0000000000006310 T MBCNodal::Close() const
0000000000008b70 T MBCNodal::GetXP(unsigned int) const
00000000000081b0 T MBCNodal::GetXP() const
0000000000007ee0 T MBCNodal::Omega(unsigned char) const
0000000000008670 T MBCNodal::Omega(unsigned int, unsigned char) const
0000000000007eb0 T MBCNodal::Theta(unsigned char) const
00000000000084a0 T MBCNodal::Theta(unsigned int, unsigned char) const
0000000000008c40 T MBCNodal::GetXPP(unsigned int) const
0000000000008260 T MBCNodal::GetXPP() const
0000000000007f00 T MBCNodal::OmegaP(unsigned char) const
00000000000087b0 T MBCNodal::OmegaP(unsigned int, unsigned char) const
0000000000005fc0 T MBCNodal::GetType() const
0000000000007ec0 T MBCNodal::Euler123(unsigned char) const
0000000000008550 T MBCNodal::Euler123(unsigned int, unsigned char) const
0000000000007f70 T MBCNodal::GetNodes() const
0000000000008bc0 T MBCNodal::GetOmega(unsigned int) const
00000000000081f0 T MBCNodal::GetOmega() const
0000000000008a70 T MBCNodal::GetTheta(unsigned int) const
00000000000080d0 T MBCNodal::GetTheta() const
0000000000006210 T MBCNodal::GetMotion() const
0000000000008cc0 T MBCNodal::GetOmegaP(unsigned int) const
00000000000082d0 T MBCNodal::GetOmegaP() const
00000000000062c0 T MBCNodal::Negotiate() const
00000000000061d0 T MBCNodal::PutForces(bool) const
000000000020dc48 V typeinfo for MBCBase
000000000020dc70 V typeinfo for MBCModal
000000000020dc58 V typeinfo for MBCNodal
000000000000b468 V typeinfo name for MBCBase
000000000000b488 V typeinfo name for MBCModal
000000000000b478 V typeinfo name for MBCNodal
000000000020dc88 V vtable for MBCBase
000000000020dd38 V vtable for MBCModal
000000000020dce0 V vtable for MBCNodal
U vtable for __cxxabiv1::__class_type_info##CXXABI_1.3
U vtable for __cxxabiv1::__si_class_type_info##CXXABI_1.3
Therefore I have the feeling that the MBCNodal class is somehow accessible with JNA. But I don't manage to figure out how?
I wish not to modify the library implementation. I have the source code of both .h and .cpp. But I don't know how it was compiled in order to produce the libmbc.so.
thanks for your help.
Edit:
here is a sample code on how I load the library and access the extern methods:
private interface Wrapper extends Library {
Wrapper INSTANCE = Native.loadLibrary( C_LIBRARY_PATH, Wrapper.class );
Pointer mbc_nodal_init(Pointer ptr, int refnode, int nodes, int label, int rot, int accels);
int mbc_nodal_get_motion(Pointer ptr);
int mbc_nodal_negotiate_request(Pointer ptr);
int mbc_nodal_put_forces(Pointer ptr, int converged);
}
You can use JNI as an adapter.
Take a look at these two samples. I guess, this is something you are looking for.
http://jnicookbook.owsiak.org/recipe-No-021/
http://jnicookbook.owsiak.org/recipe-No-023/
In both cases, you have code that will be adapted by JNI code
Of course, you have to make sure to properly map Java data to what ever is required in your .so based functions.
As for the JNA, there is quite comprehensive tutorial site here:
http://www.eshayne.com/jnaex/index.html

Inconsistent results calling DLL from JNA/C versus Pascal

I have a c++ dll library with header files provided, without implementation.
And I implement JNA call for this library functions.
And I have the problem with only 1 function (other, even similar works fine). This is declaration from .h file:
int CALLINGCONV SMIMESignML(
const char* pin,
unsigned long slot,
const char* szOutputFilePath,
const char* szFrom,
const char* szTo,
const char* szSubject,
const char* szOtherHeaders,
const char* szBody,
const char* szAttachments,
unsigned long dwFlags,
int bInitialize
);
Java code:
public interface Dll extends StdCallLibrary {
public String JNA_LIBRARY_NAME = "libname.dll";
int SMIMESignML(String pPin, int slot, String pOut, String pFrom, String pTo,
String pSubject, String pHeaders, String pBody, String pAttachments, int flags,
int init);
}
public class Test {
private static final Dll dll = (Dll) Native.loadLibrary(Dll.JNA_LIBRARY_NAME, Dll.class, W32APIOptions.ASCII_OPTIONS);
public static void main(String[] args) {
String pOut = "";
String pFrom = "";
String pTo = "";
String pBody = "";
String pAttachments = "";
int code = dll.SMIMESignML(null, 0, pOut, pFrom, pTo, null, null, pBody, pAttachments, 0, 0);
System.out.println(code);
}
}
The function should return different int error codes, but it always return code 0xFFFF.
I can check it with the same code in Pascal:
unit dll;
interface
const
JNA_LIBRARY_NAME = 'libname.dll';
function SMIMESignML(pPin: PChar; slot: integer; pOut: PChar; pFrom: PChar; pTo: PChar;
pSubject: PChar; pHeaders: PChar; pBody: PChar; pAttachments: PChar; flags: integer;
init: integer): integer; stdcall; external JNA_LIBRARY_NAME;
implementation
end.
program Hello;
uses dll;
var
code: integer;
begin
code := SMIMESignML(nil, 0, '', '', '', nil, nil, '' , '', 0, 0);
writeln(code);
end.
Pascal code returns 2, Java code return 65535. Moreover, Pascal std calls work right, changing arguments we get different error codes (0=OK and others), but Java with the same arguments is not working, it always returns 0xFFFF.
How can I debug it to understand the problem?
P.S.
Moreover, in the same library I has this function and it works from JNA without any problems:
int CALLINGCONV PKCS7SignML(
const char *pin,
unsigned long slot,
const char* szInputFileName,
const char* szOutputFileName,
int bInitialize);
The OS is Win8 x64, JavaOracle7x86, library is x32.
"unsigned long" should not be the problem, as it should be 4 bytes on windows.
What am I doing wrong, if the same STD call returns different results in this two examples? And How can I debug it?

Categories

Resources