Home > Archive > Java Help > August 2006 > Loading of dll file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Loading of dll file
|
|
| vinaymvbhat82@gmail.com 2006-08-30, 4:02 am |
| Hi,
I had a doubt in java related to loading of dll files.The first thing
is how to load the dll file in java and then how to retrive the
methods/functions from the dll files.Can anybody help me, please.
| |
| Philipp Leitner 2006-08-30, 4:02 am |
|
vinaymvbhat82@gmail.com wrote:
> Hi,
> I had a doubt in java related to loading of dll files.The first thing
> is how to load the dll file in java and then how to retrive the
> methods/functions from the dll files.Can anybody help me, please.
I am not sure what you mean with "load", but if you think about calling
functions of the DLL you'll definitely be out of luck with pure Java -
you need to go over the native interface (JNI) as soon as you want to
integrate with C(++) program code.
/philipp
| |
| Gordon Beaton 2006-08-30, 4:02 am |
| On 29 Aug 2006 23:58:44 -0700, vinaymvbhat82@gmail.com wrote:
> I had a doubt in java related to loading of dll files.The first thing
> is how to load the dll file in java and then how to retrive the
> methods/functions from the dll files.Can anybody help me, please.
System.load() or System.loadLibrary() will load a DLL.
If it's been written specifically for use with Java, the methods it
contains will belong to Java classes. You can use those methods the
same way you use any Java methods, i.e. you don't do anything
different just because they're in a DLL.
If it hasn't been written for use with Java, then you need to create a
new DLL that follows the rules and naming conventions of JNI and load
*that* instead. From there, you can make calls to the original DLL.
/gordon
--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
| |
| vinaymvbhat82@gmail.com 2006-08-31, 4:02 am |
| Hi,
Thanks for the reply, Now i have loaded the dll file using Regsvr32
command option from the windows.Now the problem is how do i import this
in my java application and use the inbuilt methods.
Gordon Beaton wrote:
> On 29 Aug 2006 23:58:44 -0700, vinaymvbhat82@gmail.com wrote:
>
> System.load() or System.loadLibrary() will load a DLL.
>
> If it's been written specifically for use with Java, the methods it
> contains will belong to Java classes. You can use those methods the
> same way you use any Java methods, i.e. you don't do anything
> different just because they're in a DLL.
>
> If it hasn't been written for use with Java, then you need to create a
> new DLL that follows the rules and naming conventions of JNI and load
> *that* instead. From there, you can make calls to the original DLL.
>
> /gordon
>
> --
> [ don't email me support questions or followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e
| |
| Gordon Beaton 2006-08-31, 4:02 am |
| On 30 Aug 2006 22:39:47 -0700, vinaymvbhat82@gmail.com wrote:
> Hi,
> Thanks for the reply, Now i have loaded the dll file using Regsvr32
> command option from the windows.Now the problem is how do i import this
> in my java application and use the inbuilt methods.
As I wrote earlier, you need to write your own DLL that follows the
JNI rules and naming conventions. For example, consider this Java
class:
public class MyClass {
public native int foo(int a);
[ ...and other methods...]
}
Note that MyClass has a native method foo(), which is found in a DLL
that has been written expressly for the purpose of implementing one or
more of the methods of MyClass:
JNIEXPORT jint JNICALL Java_MyClass_foo(JNIEnv *env, jobject this_foo, jint a)
{
return some_other_function(a);
}
From native methods like this one, any other functions can be invoked,
including those in your existing DLL.
You need to write a set of native methods like foo() that bridge
between your Java application and the library functions you want to
use.
Start reading here:
http://java.sun.com/j2se/1.5.0/docs.../jni/index.html
http://java.sun.com/docs/books/jni/index.html
/gordon
--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|
|
|
|
|