Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


(Java):How can I use API32

Posted on 2005-03-15
Medium Priority
Last Modified: 2008-01-09
Hello experts
I am using Jbuilder X For develop my application.
How can I use API32 (windows).
For example I want change screen resolution from java code.
or change Keyboard layout or ...
Thanks a lot for your HELP
Question by:ZomorodianA
  • 2
  • 2

Expert Comment

ID: 13552720
one simple way is to write a simple JNI function. From that JNI function in C++, you use API32 libary to change screen resolution.
LVL 19

Expert Comment

by:Jim Cakalic
ID: 13565690
Hi. I'd recommend looking at some of the available Java/Win32 integrations before deciding to write your own. Here's some examples. I've played with a couple of these in the distant past and they seemed to work pretty much as advertised.

(Open Source) The Java/Win32 integration project (Jawin) is a free, open source architecture for interoperation between Java and components exposed through Microsoft's Component Object Model (COM) or through Win32 Dynamic Link Libraries (DLLs).

(Commercial) The xFunction library is the universal solution for integration of Java code with code written in other languages, superior in many aspects to Java Native Interface (JNI). At the same time, xFunction itself is implemented using JNI and reflection and therefore is 100% Java 2 Runtime compatible.

(Commercial) JNIWrapper is the software development kit for working with native code from Java™ programs without using JNI. You write your code using Java only, and our product does the rest.

(Commercial) Coroutine for Java class library provides the mechanism for Java to call external functions exported from Windows dynamic link libraries. Coroutine also enables you to dynamically build callable wrappers around Java methods so external functions can call Java methods as if they are native functions.

But if you really want to go the roll your own route then here's a tutorial article that may help you get started in the right direction:

And here's another -- took a bit of googling -- that describes how to change the display settings in C++. This one is beneficial for the Win32 specifics that you'll need to know whichever way you go.



Author Comment

ID: 13580915
Hi Experts
I want Change Keyboard language (keyboar layout)
But i can not fint it in Jawin.
Please help me . where is it in Jawin?
Thanks .
LVL 19

Accepted Solution

Jim Cakalic earned 500 total points
ID: 13582501
I think that might be a combination of the win32 functions LoadKeyboardLayout and ActivateKeyboardLayout. For more information see the win32 api reference:

I broke up the URL so it wouldn't cause the site to make this page scroll horizontally.

As for calling these functions, you won't find any class or method in jawin that maps specifically to this. You would use FuncPtr. Now, I don't claim to be win32 api guru. But here's how I think it might look using jawin to invoke the necessary functions to activate the default keyboard layout for Russian based on my reading of the reference at the URL posted above.

    FuncPtr loadLayout = new FuncPtr("USER32.DLL", "LoadKeyboardLayout");
    int hkl = loadLayout.invoke("00000419", 0, ReturnFlags.DONT_CARE);
    FuncPtr activateLayout = new FuncPtr("USER32.DLL", "ActivateKeyboardLayout");
    int lastHkl = activateLayout.invoke(hkl, 0);
    if (lastHkl == 0) {
        System.err.println("Failed to activate keyboard layout");


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question