public JniTest {
  public native void test;
}然后用javah生成JniTest.h文件,修改函数声明,加入包名,规范请参考JNI规范。新建一个vc项目,选择动态连接库的向导。去掉cpp文件中的所有include(某些.h不需要)然后
include JniTest.h把你所需要的方法完成即可。编译前,需要加入jvm.h和jvm.lib到编译环境中去。
如果顺利产生dll文件,就OK了,不过不成功,多试剂此,我也是编译了好多次才通过的。

解决方案 »

  1.   

    http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html
      

  2.   

    class HelloNativeTest
    {  public static void main(String[] args)
       {  HelloNative.greeting();
       }
    }class HelloNative
    {  public static native void greeting();
       static
       {  System.loadLibrary("HelloNative");
       }
    }//file name:HelloNative.c
    #include "HelloNative.h"
    #include <stdio.h>JNIEXPORT void JNICALL Java_HelloNative_greeting
      (JNIEnv* env, jclass cl)
    {  printf("Hello world!\n");
    }//HelloNative.h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class HelloNative */#ifndef _Included_HelloNative
    #define _Included_HelloNative
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     HelloNative
     * Method:    greeting
     * Signature: ()V
     */
    JNIEXPORT void JNICALL Java_HelloNative_greeting
      (JNIEnv *, jclass);#ifdef __cplusplus
    }
    #endif
    #endif
      

  3.   

    参照<<Thinking in java>>一书的最后附录部分,讲得很清楚,而且还有例子
      

  4.   

    使用jni
    告诉你一个地址和代码
    http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.htmlclass HelloWorld {
        public native void displayHelloWorld();    static {
            System.loadLibrary("hello");
        }
        
        public static void main(String[] args) {
            new HelloWorld().displayHelloWorld();
        }
    }