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);
...
...
I've tried creating a simple jni test app from "Beginning Android Games 3rd Ed" book. I copy-pasted the code, but when I try to link with ndk-build, I get the following error messages:
D:\apps\android\projects\NDK\app\src\main\java>ndk-build
[armeabi-v7a] Compile++ arm : jniutils <= jniutils.cpp
jni/jniutils.cpp:8:52: error: format string is not a string literal (potentially insecure)
[-Werror,-Wformat-security]
__android_log_print(ANDROID_LOG_VERBOSE, cTag, cMessage);
^~~~~~~~
jni/jniutils.cpp:8:52: note: treat the string as an argument to avoid this
__android_log_print(ANDROID_LOG_VERBOSE, cTag, cMessage);
^
"%s",
1 error generated.
make: *** [obj/local/armeabi-v7a/objs/jniutils/jniutils.o] Error 1
If I try to treat these errors as warnings and suppress these with the following lines in android.mk / application.mk:
APP_CFLAGS += -Wno-error=format-security
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
Then I get this error:
D:\apps\android\projects\NDK\app\src\main\java>ndk-build
[armeabi-v7a] SharedLibrary : libjniutils.so
clang++.exe: error: no such file or directory: '遶上・llog'
make: *** [obj/local/armeabi-v7a/libjniutils.so] Error 1
Which I guess is just some garbage from memory, like a string /variable hasn't been addressed correctly.
I'm very new to jni, so I'm at a bit of a loss of how to troubleshoot this.
Code follows:
JniUtils.java
package com.badlogic.androidgames.ndk;
import java.nio.ByteBuffer;
public class JniUtils {
static {
System.loadLibrary("jniutils");
}
public static native void log(String tag, String message);
public static native void copy(ByteBuffer dst, float[] src, int offset, int len);
}
jniutils.cpp
#include <android/log.h>
#include <string.h>
#include "jniutils.h"
JNIEXPORT void JNICALL Java_com_badlogic_androidgames_ndk_JniUtils_log
(JNIEnv *env, jclass clazz, jstring tag, jstring message) {
const char *cTag = env-> GetStringUTFChars(tag, 0);
const char *cMessage = env-> GetStringUTFChars(message, 0);
__android_log_print(ANDROID_LOG_VERBOSE, cTag, cMessage);
env-> ReleaseStringUTFChars(tag, cTag);
env-> ReleaseStringUTFChars(message, cMessage);
}
JNIEXPORT void JNICALL Java_com_badlogic_androidgames_ndk_JniUtils_copy
(JNIEnv *env, jclass clazz, jobject dst, jfloatArray src, jint offset, jint len) {
unsigned char* pDst = (unsigned char*)env-> GetDirectBufferAddress(dst);
float* pSrc = (float*)env-> GetPrimitiveArrayCritical(src, 0); memcpy(pDst,
pSrc + offset, len * 4);
env-> ReleasePrimitiveArrayCritical(src, pSrc, 0);
}
application.mk
APP_ABI := armeabi-v7a x86
APP_PLATFORM := android-19
android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := jniutils
LOCAL_LDLIBS := − llog
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := jniutils.cpp
include $(BUILD_SHARED_LIBRARY)
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
I used to have some privilege issues when calling ExitWindowsEX Windows API function.
So I wrote the following code to get the privilege:
This works fine in C++
#include <cstdlib>
#include <windows.h>
#include <iostream>
using namespace std;
/*
*
*/
int MyExitWindows(int flag, int reason);
int main(int argc, char** argv) {
MyExitWindows(EWX_SHUTDOWN, 0);
}
int MyExitWindows(int flag, int reason) {
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return GetLastError();
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
ExitWindowsEx(flag, reason);
if (GetLastError() != ERROR_SUCCESS) {
return GetLastError();
}
return 0;
}
But this doesn't work when I call it from Java
#include <jni.h>
#include <cstdlib>
#include <windows.h>
#include "com_ehsunbehravesh_jshutdown_system_Shutdowner.h"
using namespace std;
int MyExitWindows(int flag, int reason);
JNIEXPORT jint JNICALL Java_com_ehsunbehravesh_jshutdown_system_Shutdowner_exitWindowsEx
(JNIEnv *env, jobject obj, jlong flag, jlong reason) {
return MyExitWindows(flag, reason);
}
int MyExitWindows(int flag, int reason) {
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
int cpid = GetCurrentProcessId();
printf("%d", cpid);
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return GetLastError();
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
ExitWindowsEx(flag, reason);
if (GetLastError() != ERROR_SUCCESS) {
return GetLastError();
}
return 0;
}
Is there any reason you are not using System.exit(int)?
Java attempts to control the shutdown of an application, perhaps it tries to prevent you doing it other ways.