上面的程序是java2dll.c,偶老是编译不通过???

解决方案 »

  1.   

    贴出错误代码,是 UnSatisfiedLink ?只要你有编译好的 dll 就可以了,至于 lib 是编译生成 dll 时候要用的吧,和 jni 没有关系的,只要能编译成功 dll 就可以了
      

  2.   

    这是偶的全部代码
    t.c#include <stdio.h>
    #include "Java2DocdllAccess.h"int RunDllInit(char* fileName)
    {
      void (*MYPROC)(void);
      HINSTANCE hlib;
      int (*LOAD)(char* fileName);//定义函数指针
      int retvalue; //函数返回
      
      LOAD lpFunc;
      hLib=LoadLibrary("Maker.dll");
      if(hLib==NULL)
      {
          printf("exit load dll");
          exit(-1);
      }
      
      AfxSetResourceHandle(hLib); 
       //调用name.dll的方法Abstract  
      lpFunc=(LOAD)GetProcAddress(hLib,"Init");
      if(lpFunc==NULL)
      {
          printf("exit load fun");
          exit(-1);
      }  retvalue = (lpFunc)(fileName);
      FreeLibrary(hLib);  return retvalue;
    }
    JNIEXPORT jlong JNICALL Java_Java2DocdllAccess_RunDllInit
      (JNIEnv *env, jobject obj)
    {
         return RunDllInit();
    }
    int RunDllNewDoc(char* fileName)
    {
      void (*MYPROC)(void);
      HINSTANCE hlib;
      int (*LOAD)(char* fileName);//定义函数指针
      int retvalue; //函数返回
      
      LOAD lpFunc;
      hLib=LoadLibrary("Maker.dll");
      if(hLib==NULL)
      {
          printf("exit load dll");
          exit(-1);
      }
      
      AfxSetResourceHandle(hLib); 
       //调用name.dll的方法Abstract  
      lpFunc=(LOAD)GetProcAddress(hLib,"NewDoc");
      if(lpFunc==NULL)
      {
          printf("exit load fun");
          exit(-1);
      }  retvalue = (lpFunc)(fileName);
      FreeLibrary(hLib);  return retvalue;
    }
    JNIEXPORT jlong JNICALL Java_Java2DocdllAccess_NewDoc
      (JNIEnv *env, jobject obj, jstring str1, jstring str2)
    {
         return RunDllNewDoc(str1,str2);
    }  
      

  3.   

    这是用VC调试的结果--------------------Configuration: t - Win32 Debug--------------------
    Compiling...
    t.c
    c:\dll\t.c(7) : error C2065: 'HINSTANCE' : undeclared identifier
    c:\dll\t.c(7) : error C2146: syntax error : missing ';' before identifier 'hlib'
    c:\dll\t.c(7) : error C2065: 'hlib' : undeclared identifier
    c:\dll\t.c(8) : error C2143: syntax error : missing ';' before 'type'
    c:\dll\t.c(9) : error C2143: syntax error : missing ';' before 'type'
    c:\dll\t.c(11) : error C2065: 'LOAD' : undeclared identifier
    c:\dll\t.c(11) : error C2146: syntax error : missing ';' before identifier 'lpFunc'
    c:\dll\t.c(11) : error C2065: 'lpFunc' : undeclared identifier
    c:\dll\t.c(12) : error C2065: 'hLib' : undeclared identifier
    c:\dll\t.c(12) : warning C4013: 'LoadLibrary' undefined; assuming extern returning int
    c:\dll\t.c(13) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'
    c:\dll\t.c(16) : warning C4013: 'exit' undefined; assuming extern returning int
    c:\dll\t.c(19) : warning C4013: 'AfxSetResourceHandle' undefined; assuming extern returning int
    c:\dll\t.c(21) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
    c:\dll\t.c(21) : warning C4013: 'GetProcAddress' undefined; assuming extern returning int
    c:\dll\t.c(22) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'
    c:\dll\t.c(28) : error C2065: 'retvalue' : undeclared identifier
    c:\dll\t.c(28) : error C2064: term does not evaluate to a function
    c:\dll\t.c(29) : warning C4013: 'FreeLibrary' undefined; assuming extern returning int
    c:\dll\t.c(38) : error C2198: 'RunDllInit' : too few actual parameters
    c:\dll\t.c(45) : error C2146: syntax error : missing ';' before identifier 'hlib'
    c:\dll\t.c(46) : error C2143: syntax error : missing ';' before 'type'
    c:\dll\t.c(47) : error C2143: syntax error : missing ';' before 'type'
    c:\dll\t.c(49) : error C2146: syntax error : missing ';' before identifier 'lpFunc'
    c:\dll\t.c(51) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'
    c:\dll\t.c(59) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
    c:\dll\t.c(60) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'
    c:\dll\t.c(66) : error C2064: term does not evaluate to a function
    c:\dll\t.c(74) : warning C4133: 'function' : incompatible types - from 'struct _jobject *' to 'char *'
    c:\dll\t.c(74) : warning C4020: 'RunDllNewDoc' : too many actual parameters
    Error executing cl.exe.t.obj - 19 error(s), 11 warning(s)
      

  4.   

    可能是 vc 配置路径的先后问题,查看一下.现在的问题是出在 vc 编译生成 dll 出错,而不是 java 的问题,对于  vc 编译时引入 lib 的路径,有时候先后的次序不同可能会造成编译出错,检查一下.另外看看语法是否有问题!