On 9 Aug 2005 05:22:38 -0700,
wrote:
> I used the "Dependency Walker", and found there is nothing in DLL !
> This is strange!
>
> When there is no package information in Java codes, I succeeded calling
> C++ from Java. The DLL produced is like this:
>
> Ordinal: 1 (0x0001)
> Hint: 0 (0x0000)
> Funtion: _Java_NatBE_calculateBE@24
> Entry Point: 0x00001573
>
> With the package information in Java codes, the same C++ source codes
> were used, except the h file produced by javah. One DLL was produced
> but nothing in it. Why is it like this?
"Nothing" sounds strange and unexpected. However you should not expect
to use the exact same source in both cases, since the generated method
names will be different, and this difference needs to be reflected in
the names of your native methods.
The advice I have when using native methods with packages is this
(actually this holds even without packages):
- specify the fully qualified classname when you run javah.
- #include the generated header file in your C or C++ file.
- make sure your names and signatures are *exactly* identical with the
generated ones.
An alternative solution is to define a function JNI_OnLoad() in your
library, from which you invoke RegisterNatives() to register the set
of native methods for the class.
In that case your native methods don't need to obey the generated
names at all (in fact I usually prefer to give them shorter names that
more closely match the native declarations in the java source). You
still need the information from javah in order to create the table
mapping names and signatures to their corresponding methods though.
When using this mechanism, the *only* difference between the packaged
and packageless versions is the way you spell the classname in the
call to RegisterNatives().
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e