|
Define the following prototype in the header file
JNIEXPORT void JNICALL Java_JavaHowTo_setSystemTime
(JNIEnv *, jobject, jshort, jshort);
the JNI function
JNIEXPORT void JNICALL Java_JavaHowTo_setSystemTime
(JNIEnv *env, jobject obj, jshort hour, jshort minutes) {
SYSTEMTIME st;
GetLocalTime(&st);
st.wHour = hour;
st.wMinute = minutes;
SetLocalTime(&st);
}
The Java JNI wrapper would be
class JavaHowTo {
public native void setSystemTime( short hour, short minutes);
static {
System.loadLibrary("javahowto");
}
}
|
And finally, to use it
public class JNIJavaHowTo {
public static void main(String[] args) {
short hour = 10;
short minutes = 21;
// this example will set the system at 10h21 using the Windows API
// SetLocalTime.
JavaHowTo jht = new JavaHowTo();
// set the time at 10h21
jht.setSystemTime(hour, minutes);
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.