first time use JNI success with WinApi .great.
2004-03-22 15:54
369 查看
1:copy jni.h to project dir,and rename jni2.h,if not alert error,do not know why.
2:write a java to use jni,
3:use javah create a header file.
4:write implemention of the header,useing MsgBox();
5:comile with user32.lib just append:
C:\JNI>cl -IdC:\j2sdk1.4.1\include -I c:\j2sdk1.4.1\include\win32 -LD HelloWorld
Imp.c -Fehello.dll user32.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
HelloWorldImp.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/dll
/implib:hello.lib
/out:hello.dll
HelloWorldImp.obj
user32.lib
Creating library hello.lib and object hello.exp
C:\JNI>java HelloWorld
Hello world!
//and also have a Window!!.
all file:
1:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni2.h"
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
2:
//±¾ÀýÖÐÆðÃûΪHelloWorldImp.c
#include "jni2.h"
#include "HelloWorld.h"
#include <stdio.h>
#include "windows.h"
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");//Õâ¸öÀý×ÓÖÐÖ»Êä³öÒ»ÐÐHello World!
//CreateWindow("BUTTON","",NULL,NULL,NULL);
MessageBox(NULL,"OK","OK",MB_OK);
return;
}
3:
C:\JNI>cl -IdC:\j2sdk1.4.1\include -I c:\j2sdk1.4.1\include\win32 -LD HelloWorld
Imp.c -Fehello.dll user32.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
HelloWorldImp.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/dll
/implib:hello.lib
/out:hello.dll
HelloWorldImp.obj
user32.lib
Creating library hello.lib and object hello.exp
C:\JNI>java HelloWorld
Hello world!
C:\JNI>
2:write a java to use jni,
3:use javah create a header file.
4:write implemention of the header,useing MsgBox();
5:comile with user32.lib just append:
C:\JNI>cl -IdC:\j2sdk1.4.1\include -I c:\j2sdk1.4.1\include\win32 -LD HelloWorld
Imp.c -Fehello.dll user32.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
HelloWorldImp.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/dll
/implib:hello.lib
/out:hello.dll
HelloWorldImp.obj
user32.lib
Creating library hello.lib and object hello.exp
C:\JNI>java HelloWorld
Hello world!
//and also have a Window!!.
all file:
1:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "jni2.h"
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloWorld
* Method: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
2:
//±¾ÀýÖÐÆðÃûΪHelloWorldImp.c
#include "jni2.h"
#include "HelloWorld.h"
#include <stdio.h>
#include "windows.h"
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");//Õâ¸öÀý×ÓÖÐÖ»Êä³öÒ»ÐÐHello World!
//CreateWindow("BUTTON","",NULL,NULL,NULL);
MessageBox(NULL,"OK","OK",MB_OK);
return;
}
3:
C:\JNI>cl -IdC:\j2sdk1.4.1\include -I c:\j2sdk1.4.1\include\win32 -LD HelloWorld
Imp.c -Fehello.dll user32.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
HelloWorldImp.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
/dll
/implib:hello.lib
/out:hello.dll
HelloWorldImp.obj
user32.lib
Creating library hello.lib and object hello.exp
C:\JNI>java HelloWorld
Hello world!
C:\JNI>
相关文章推荐
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- First time play with JavaCV/OpenCV to detect faces
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- 'sizeWithFont:' is deprecated: first deprecated in iOS 7.0 - Use -sizeWithAttributes:
- the first time use the header of zlib.h
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- sizeWithFont:constrainedToSize:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithS
- ValueError: Attempt to reuse RNNCell <tensorflow.contrib.rnn.python.ops.core_rnn_cell_impl.BasicLSTMCell object at 0x7f1a3c448390> with a different variable scope than its first use.解决方法
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- this is the first time to use this.
- JNI运行Error:error: linker command failed with exit code 1 (use -v to see invocation)解决
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- Google powers a data center directly with wind for the first time
- Oracle TTS ORA-39322: Cannot use transportable tablespace with different timezone version 说明
- Given a list of presentations with begin and end time that all need to use a conference room.
- First Time Use It
- first time to use github
- First Time Use It