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

解决方案 »

  1.   

    以前同事说方法参数的设计好像有限制,不仅名称一样,参数类型也要一样,而且还只能是string对象。好像是这样的!试试吧
      

  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)