(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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

801 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