Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: call win32 api from java

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile call win32 api from java

    how can i call win32 API from java using JNI?
    i don't want to use other commercial packages to download and install.
    it should be done only by jvm and i have vc++ installed.
    plz submit any code and steps required to do so?
    i tried this but does not work and gives runtime error :
    public class NewMain
    {
            static{System.load("C:\\WINDOWS\\system32\\kernel32.dll");}
            native private static short GetSystemDefaultLangID();
     
            public static void main(String ss[])
            {
                System.out.print(GetSystemDefaultLangID());
            }
     
    }
    Last edited by helloworld922; November 1st, 2010 at 07:50 PM.


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: call win32 api from java

    Please use highlight tags. If you're unsure how to get started with JNI, I would suggest looking at Chapter 5 Continued: JNI Example and Enhance your Java application with Java Native Interface (JNI) - JavaWorld

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: call win32 api from java

    Wheres Freaky Chris when you need him!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  4. #4
    Member
    Join Date
    May 2010
    Posts
    39
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: call win32 api from java

    I recomend using JNA, Website Here

    It's much more simplistic,

    Then use this sample code:
    import com.sun.jna.Native;
    import com.sun.jna.win32.StdCallLibrary;
     
    public interface Kernel32 extends StdCallLibrary {
     
        Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
     
        short GetSystemDefaultLangID();
     
    }

    Accessing it as:
    Kernel32.INSTANCE.GetSystemDefaultLangID()

    If you have any questions Id be happy to explain

Similar Threads

  1. [SOLVED] Trying to call web service (and failing)
    By jamesruk21 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 15th, 2011, 12:35 PM
  2. call recording throuph java
    By 7121987 in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: April 29th, 2010, 05:12 PM
  3. JSP freezes after AJAX call !!
    By java_freek in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: April 16th, 2010, 11:31 AM
  4. need programmer for my online call center
    By erinbasim in forum Paid Java Projects
    Replies: 6
    Last Post: March 30th, 2010, 02:45 AM
  5. Under Windows OS, how to call *.EXE produced in Linux OS?
    By tony_lincoln in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 19th, 2010, 01:51 AM