Newbie question about connecting C++ with Java with JNI

W

wignas

Hi all, I have a question and would really appreciate any help with
this.

So, I have connected a Java class and a Visual Studio C++ Dll-project
using JNI:


#include <windows.h>
#include <string.h>
#include "prog1.h" //The machine generated header file
#include "Logic.h" //I want to use the methods in this header


BOOL WINAPI DllMain(HANDLE hHandle, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}

JNIEXPORT jint JNICALL Java_prog1_Sum(JNIEnv *, jclass, jint a, jint b)
{
//TestJava(); //This wont work :(
return a + b;
}

JNIEXPORT jstring JNICALL Java_prog1_saySomething(JNIEnv * env, jclass,
jstring strString)
{
char *lpBuff = (char*)env->GetStringUTFChars(strString, 0);
_strupr(lpBuff);
jstring jstr = env->NewStringUTF(lpBuff);
env->ReleaseStringUTFChars(strString, lpBuff);
return jstr;
}


I have tested to use this JNI-methods from Java and it works fine, but
now I want call my old C/C++ methods in "Logic.h" from this JNI
interface. How do I do that? Say I have a simple method in Logic.c like
this:

extern void TestJava()
{
CAN_DATA_WriteConvX myConv1Settings;
myConv1Settings.Motor0 = MotorOn;
outputConv1(myConv1Settings);
}

I can't call this from my JNIEXPORT methods, but I can call it from any
other "ordinary" cpp method. So how should I do for using the old
methods in Logic.h from Java?


Thanks for any help. /Jonas
 
R

Roland Pibinger

So, I have connected a Java class and a Visual Studio C++ Dll-project
using JNI:

Questions about JNI and VS-Dlls are not really on topic in a pure C++
news group.
I can't call this from my JNIEXPORT methods, but I can call it from any
other "ordinary" cpp method. So how should I do for using the old
methods in Logic.h from Java?

Use the 'ordinary' functions. The functions generated for JNI are just
wrappers for the 'old methods' to make them callable from Java.

Best wishes,
Roland Pibinger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top