高分求:用过jni的朋友帮我看看偶的程序错在哪? 上面的程序是java2dll.c,偶老是编译不通过??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 贴出错误代码,是 UnSatisfiedLink ?只要你有编译好的 dll 就可以了,至于 lib 是编译生成 dll 时候要用的吧,和 jni 没有关系的,只要能编译成功 dll 就可以了 这是偶的全部代码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);} 这是用VC调试的结果--------------------Configuration: t - Win32 Debug--------------------Compiling...t.cc:\dll\t.c(7) : error C2065: 'HINSTANCE' : undeclared identifierc:\dll\t.c(7) : error C2146: syntax error : missing ';' before identifier 'hlib'c:\dll\t.c(7) : error C2065: 'hlib' : undeclared identifierc:\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 identifierc:\dll\t.c(11) : error C2146: syntax error : missing ';' before identifier 'lpFunc'c:\dll\t.c(11) : error C2065: 'lpFunc' : undeclared identifierc:\dll\t.c(12) : error C2065: 'hLib' : undeclared identifierc:\dll\t.c(12) : warning C4013: 'LoadLibrary' undefined; assuming extern returning intc:\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 intc:\dll\t.c(19) : warning C4013: 'AfxSetResourceHandle' undefined; assuming extern returning intc:\dll\t.c(21) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'c:\dll\t.c(21) : warning C4013: 'GetProcAddress' undefined; assuming extern returning intc:\dll\t.c(22) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'c:\dll\t.c(28) : error C2065: 'retvalue' : undeclared identifierc:\dll\t.c(28) : error C2064: term does not evaluate to a functionc:\dll\t.c(29) : warning C4013: 'FreeLibrary' undefined; assuming extern returning intc:\dll\t.c(38) : error C2198: 'RunDllInit' : too few actual parametersc:\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 functionc:\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 parametersError executing cl.exe.t.obj - 19 error(s), 11 warning(s) 可能是 vc 配置路径的先后问题,查看一下.现在的问题是出在 vc 编译生成 dll 出错,而不是 java 的问题,对于 vc 编译时引入 lib 的路径,有时候先后的次序不同可能会造成编译出错,检查一下.另外看看语法是否有问题! 堆栈溢出的问题,请帮忙解决一下 java dom 查找指定节点 求救,如何判断空工作表 Socket单通道异步长连接多客户端的消息返回问题 java的程序 谁能帮我解释一下? 招募斑竹。 读excel的问题,在线等... 谁有keytool的中文文档? win2000 professional下如何配置weblogic6.0 在java程序中执行javac的问题 Vector
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);
}
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)