c++ 事件回调 java
#pragma once #ifdef __cplusplus extern "C" { #endif typedef void(*sig_t)(int); int FirstEliteValidateTest(); int FirstEliteValidateTest2(sig_t proc); #ifdef __cplusplus } #endif
package com.bg.security; import com.sun.jna.Callback; import com.sun.jna.Library; import com.sun.jna.Native; import java.io.File; import java.io.IOException; import java.util.Properties; public class Program4Linux { public interface CLibrary extends Library { interface sig_t extends Callback { void invoke(int signal); } int FirstEliteValidateTest(); int FirstEliteValidateTest2(sig_t proc); } public static void main(String[] args) throws InterruptedException, IOException { CLibrary lib = (CLibrary) Native.load("FirstEliteValidate", CLibrary.class); int a = lib.FirstEliteValidateTest(); System.out.println("a=" + a); CLibrary.sig_t fn = new CLibrary.sig_t() { public void invoke(int sig) { System.out.println("signal " + sig + " was raised"); } }; int b = lib.FirstEliteValidateTest2(fn); System.out.println("b=" + b); Properties props = System.getProperties(); System.out.println("Operating System:" + props.getProperty("os.name")); System.out.println("System Version:" + props.getProperty("os.version")); System.out.println("end"); } }
桂棹兮兰桨,击空明兮溯流光。