Java Examples
This page is intended to be a repository for useful examples of using the C/Invoke Java Binding, as a companion for the reference documentation. We are just getting started for now so the supply is a little low; if you have a useful example to share please help us out by submitting it to the mailing list.
Linux getpass()
The same example from the Lua page, translated into Java:
import org.cinvoke.*; class GetPass { interface libc { String getpass(String prompt); } public static void main(String[] args) { libc c = (libc)CInvoke.load("libc.so.6", libc.class); System.out.println("You entered: " + c.getpass("Enter password: ")); } }
Win32 Example
This example shows how to get the screen resolution by calling the Win32 API:
import org.cinvoke.*; class Win32Test { interface User32 { public NativeInt GetSystemMetrics(NativeInt nIndex); } private static final NativeInt SM_CXSCREEN = new NativeInt(0); private static final NativeInt SM_CYSCREEN = new NativeInt(1); public static void main(String[] args) { User32 u = (User32)CInvoke.load("User32.dll", User32.class, CInvoke.CC.STDCALL); System.out.println("Your monitor resolution is " + u.GetSystemMetrics(SM_CXSCREEN) + "x" + u.GetSystemMetrics(SM_CYSCREEN)); } }