Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Windows api thro Jni--- very urgent

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to call the FindExecutable method in Shell32.dll thro a java stand alone progam.The code I have written works beautifully in VJ++.But when I run it at Dos prompt, it gives UnsatisfiedLinkError.Perhaps I should write a c function calling this FindExecutable method. And then I call the new c function thro jni in java. Can somebody help me.
The code is as below
class Editor {
public static native int FindExecutable(String lpFile, String lpDirectory, StringBuffer lpResult);

static {
System.loadLibrary("Shell32");
}

public static void main(String[] args) {
String temp_title="temp1.xls";
StringBuffer result=new StringBuffer(1024);
String temp="c:\\";
try{
int ireturn=new Editor().FindExecutable(temp_title,temp,result);
if(ireturn<32)
System.out.println("not found");
else
System.out.println(result);
}
catch(Exception e)
{
e.printStackTrace();
}

}
}
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to use JNI (Java Native Interface) to call the DLL.
Here is a description: http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
And a tutorial:
http://java.sun.com/docs/books/tutorial/native1.1/index.html
Here is a discussion of DLL handling from another forum: http://www.javaranch.com/ubb/Forum45/HTML/000115.html
 
Sucheta Gautham
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
Thanks for the immediate response.My problem has been solved.I have compiled a c++ program calling the FindExecutable method by linking shell32.lib while making the dll.Now My java program loads the new dll and my program works fine.
Now I have a new query :
Can I make an applet access a dll.If so how?
Thank you,
Sucheta
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic