Article View: borland.public.jbuilder.java.language
Article #688Re: Calling a dll func from Java
From: Alexey N. Solofnenko
Date: Fri, 25 Feb 2005 20:15
Date: Fri, 25 Feb 2005 20:15
70 lines
3470 bytes
3470 bytes
You cannot call any function from a dll. First you need to run javah to
create C or C++ header file from your compiled Java class. After that
you will need to implement that method to call native method with
correct parameters.
- Alexey.
Chris Lafferty wrote:
> Kevin,
>
> I am having a similar problem. I have done what you suggested below, adding
> the -Djava.library.path= to the location of the .DLL. It seems more like it
> cannot find the function inside the DLL as opposed to the DLL itself as
> before I copied the DLL to that location, the error described the DLL name
> instead of the funciton. I wrote a test DLL and was able to call it from
> Delphi, so I know the methods are public and exported properly. However,
> when I run from java, I get the same error as yc did. Here is my code and
> error:
>
> public class DLLBridge
> {
> public DLLBridge() {
> }
> public native void RprtMain();
>
> static{
> System.loadLibrary("Reports");
> }
>
> public static void main(String[] args) {
> DLLBridge dbridge = new DLLBridge();
> dbridge.RprtMain();
> }
> }
>
> java.lang.UnsatisfiedLinkError: RprtMain
> at com.util.DLLBridge.RprtMain(Native Method)
> at com.util.DLLBridge.main(DLLBridge.java:21)
> Exception in thread "main"
>
> Is there something I'm missing? Thanks in advance,
> Chris
>
> "Kevin Dean [TeamB]" <NkOdSePaAnM@datadevelopment.com> wrote in message
> news:xn0dyx2iu419bb001-kdean@www.teamb.com...
>
>>yc wrote:
>>
>>
>>>Hi,
>>>I have a c dll (MyDll) stdcall fnc as follows.
>>>stdcall int MyFnc(int FileNo, int IOType, unsigned char *
>>>DataToWrite, unsigned char * DataRead);
>>>
>>>I try to call from java code, but it gives me an error as follows.
>>>
>>>Exception in thread "main" java.lang.UnsatisfiedLinkError: Myfunc
>>> at X.MyFnc(Native Method)
>>> at X.main(X.java:6)
>>>
>>
>>That means that the Java process can't find the DLL in the system path.
>>Make sure that you add the appropriate directory to the PATH statement
>>or add -Djava.library.path=<dll_location> to the command line.
>>
>>--
>>Kevin Dean [TeamB]
>>Dolphin Data Development Ltd.
>>http://www.datadevelopment.com/
>>
Technical Details
Message-ID:
<421f874d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<421eedd1$2@newsgroups.borland.com> <xn0dyx2iu419bb001-kdean@www.teamb.com> <421f8461$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,a69aa8c14ff32559 X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 25 Feb 2005 12:15:13 -0800 From: "Alexey N. Solofnenko" <trelony@mail.ru> User-Agent: Mozilla Thunderbird 1.0+ (Windows/20050224) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: Calling a dll func from Java References: <421eedd1$2@newsgroups.borland.com> <xn0dyx2iu419bb001-kdean@www.teamb.com> <421f8461$1@newsgroups.borland.com> In-Reply-To: <421f8461$1@newsgroups.borland.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 208.200.221.5 Message-ID: <421f874d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1109362509 208.200.221.5 (25 Feb 2005 12:15:09 -0800) Lines: 70 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail