× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Re calling DLL in Java
  • From: "Larry Loen" <lwloen@xxxxxxxxxx>
  • Date: Thu, 17 May 2001 10:35:52 -0500
  • Importance: Normal


Quote:

   /** @dll.import("thedll.dll") */
   static native int initFunction(int sessionHandle[],
   StringBufferUserName,  int fExclusive,  int lpErrorProc[]);

   errorCode =  initFunction(sessionHandle, UserName,  1,  errorProc);

   The call is ok, errorCode = 0 and the sessionHandle contains a number
   (always the same) - 22879572
   however, when I call the function from a c++ program, the number (always
   the same) is 6832704.

   I beleive the function is working but somehow the sessionHandle is
   incorrect.
   Calling a subsequent function with the sessionHandle results in an
   errorCode that the initFunction has not
   been called.

    I have read all documentation I can find but cannot get it to work.

   Mike

A ULONG is an unsigned 32 bit integer.  Presuming you are returning an int
(formally, jint for a native method), you must realize that it will be
treated as signed by Java, having no notion of unsigned integers.  It's the
same 32 bits, just interpreted differently.  If you're doing no math on it,
that's not a big problem, though it can confuse you on output as this
distinction is easy to forget.

But, I have a few more questions.

Exactly what is on the C/C++ side of this?  Did you include jni.h?  Does
your method signature have a jint in it?  Are you using extern "C" under
C++?  What "load" statement is in your static init code for the class this
native method defines?  As far as I know, just having a special comment
does nothing in terms of loading a native method.  Nor can you expect to
simply call any old DLL as a native method, IIRC.  It's been a while since
I coded one (and the docs are a bit obscure and, of course,
platform-and-JVM dependent), but it does take a little work on the C/C++
side of it, even if you are just returning an integer of some kind (which
is about the only part that works like an ordinary function call).

Your description kind of sounds like you didn't "load" the native method
and you somehow got a nooping call without it.  I don't know how to do
that, but then, I don't run every JVM in the world and some of this
behavior is probably unspecified by Javasoft.  If that's what's happening,
then what you are seeing is garbage.

It is also true that you can't assume that   int sessionHandle[] works
exactly like C arrays when you receive it in your native method.  In fact,
in the JVMs I know about, it is guaranteed _not_ to work that way.  You
need to make special jni calls to manipulate arrays passed into a native
method IIRC.  So, if this is some sort of standard DLL, you need to provide
some translation/glue code before you invoke it to translate between Java
and C conventions.


Larry W. Loen  -   Senior Java and iSeries Performance Analyst
                          Dept HP4, Rochester MN


+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.