470,870 Members | 1,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

header file to include java classes?

I'm working on a Migration project (Forte to JAVA).

The forte client had a C++ dll which used to call one more FORTE dll
for a complex database calculations.

Now all the forte code has been migrated to JAVA except this piece of
code where C++ dll calls Forte DLL.
I'm using JNI to call the Java classes from C++. Some of the methods
in C++ has the header files where the signature has reference to the
Forte Classes (Which are now Java Classes).

How do I change the header files to include Java classes in the

(I couldnt find a strong reference for this, but i assume that for all
the classes in Java I'll need to create the .h file using javah
Here is the Sample in one of the C++ header files:

qqhConnectionHandleClass * m_ForteConnHandle; //
qqhConnectionHandleClass was Forte class which is now a
ConnectionHandleClass in Java.
HWND m_hwndParent;
int m_autocommit;
StatementHandle * m_StmtHandles;

Almost all the signatures in the header files of C++, have references
to Forte / Java classes.

Do I need to use javah and create a header file for the classes and
then include in the C++ header file?
In the implementation class (C++) just including jni.h solves my
problem as it is enough to create the jvm and loading classes/
executing methods..
Any help is appreicated.

Newbie in C++ :)


Dec 19 '07 #1
1 2638
On Dec 19, 4:22 pm, Swapnil Kale <swapnil.k...@gmail.comwrote:
Now How do I refer this converted Java Class in the C++ header.

How do I tell the C++ header where to look for the Java classs?
I believe you can't use the whole Java class in C++ through JNI. JNI
is used to access and call member functions. The 'native' Java keyword
refers to functions that run outside the JVM, but not to classes

If you use javah on a Java member function (well, on a .java file but
you get what i mean), you get a C++ header with also a parameter that
is a handle to that Java object. You can use that handle to get access
to other variables of that class and stuff like that through the JNI
API. You also have similar access to objects that are parameters to
the function call. But you don't get a full class in the C++ header.

Why do you need the full Java Class in C++? If, for example, you are
trying to create an object through its Java class in C++, i doubt you
would be able to do it directly. JNI might provide functionality for
something like that, though, but i didn't need it so I didn't
research :) However I don't recall seeing anything like that, either.
However, you could create that Java object through a Java factory,
that returns an instance of that Java object, that C++ can have access

Are you trying to have a C++ executable that creates the JVM? In that
case, from what I understand, it might be better to have a Java jar
that loads a C++ library that only deals with the dll.

Think of JNI as a bridge between functions, not classes. Besides,
classes are a compile-time construct and objects are a run-time one.
This communication is done dynamically, so you have to deal with

Forgive my horrible terminology, I was in a hurry :)
Dec 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Hattuari | last post: by
11 posts views Thread by Steven T. Hatton | last post: by
4 posts views Thread by rajkirangrandhi | last post: by
15 posts views Thread by Kannan Goundan | last post: by
4 posts views Thread by Adam Clauss | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.