× 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: MBarton@xxxxxxxxxx
  • Date: Fri, 18 May 2001 09:00:46 +0100




Larry
Thanx for your response. As always, one (me in this case) inevitably
forgets
to include some of the useful details...

I am using M$ J++ (N.B. non-std JVM) and have tried other simpler examples
to call dll's which work fine e.g.

/** @dll.import("KERNEL32") */
native static boolean GetDiskFreeSpace(String s, int i[], int j[], int k[],
int l[]);

int a[] = {0};
int b[] = {0};
int c[] = {0};
int d[] = {0};

GetDiskFreeSpace("c:\\",a,b,c,d);

note the use of int arrays for pointers to ints.

>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.
>

I am indeed only passing the handle back as a parameter to other function &
performing no maths on it.

>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).
>

The C side of it - the function as defined in c is :
USHORT  errorCode initFunction(ULONG *sessionHandle , char *username, short
exclusive, ULONG *errorProc)
The c++ program (using M$ c++ v6 ) used a supplied library to link to the
dll.
there are no special includes other than the one supplied for the
application in question.

The platform will be win32 and the jvm will be M$.

>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.
>

I have called the function with incorrect number of parameters as well as
an incorrect userName & can confirm that the return errorCode does get set.

>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.

Because the native function asks for a pointer to an int, the only way to
get java to
pass a pointer to an int is by creating a 1 element array of an int.

Having read the documentation on the ms development site, eg:
http://msdn.microsoft.com/library/devprods/vs6/visualj/vjcore/vjconquickreference.htm

Any ideas ?

Mike



+---
| 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.