• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Using JNI to call MS Windows API functions

 
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all!
for last few days I'm working on calling "user32.dll" functions from Java(I need it). I have progressed but have not succeeded yet. the first sample I'm working on is a self created .dll file but i have problems creating .dll file using cl.exe. while calling happens what follows:
>cl HelloWorld..c -IC:\Program Files\Java\jdk1.6.0_10\include -fehello.dll -MD -
LD
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '-fehello.dll'
cl : Command line warning D9024 : unrecognized source file type 'Files\Java\jdk1
.6.0_10\include', object file assumed
HelloWorld..c
HelloWorld..c(1) : fatal error C1083: Cannot open include file: 'jni.h': No such
file or directory


and secondly I wonder how to call a"user32.dll" file from java.

thanks
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to put quotes around your include path, because the command line shell now sees it as two different arguments. Try one of the following:
"-IC:\Program Files\Java\jdk1.6.0_10\include"
-I"C:\Program Files\Java\jdk1.6.0_10\include"

I think it should be the first one but I haven't tried it out.
 
ali honarmand
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:You need to put quotes around your include path, because the command line shell now sees it as two different arguments. Try one of the following:
"-IC:\Program Files\Java\jdk1.6.0_10\include"
-I"C:\Program Files\Java\jdk1.6.0_10\include"

I think it should be the first one but I haven't tried it out.



Hi Rob, Thanks, It works and the dll file is created in accompany with some other files like filename.exp, filename.obj, and etc. but while using it in my app I face this message:
java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jdk1.6.0_10\include\HelloWorld..dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at HelloWorld.<clinit>(HelloWorld.java:19)
a message appears and the exception is thrown:
Exception in thread "main"

what are dependent libraries?
 
ali honarmand
Ranch Hand
Posts: 32
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:You need to put quotes around your include path, because the command line shell now sees it as two different arguments. Try one of the following:
"-IC:\Program Files\Java\jdk1.6.0_10\include"
-I"C:\Program Files\Java\jdk1.6.0_10\include"

I think it should be the first one but I haven't tried it out.



Something I want to say, when cl is used for MS Windows native dlls a .exe file will be created, even if you have no errors. according to documents from sun: "Static or archive libraries are compiled into an executable and cannot be loaded at runtime".
 
Seriously? That's what you're going with? I prefer this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic