社区
Java SE
帖子详情
新手问题之五:JAVA中怎样调用WINDOWS的DLL中的函数?
lwg7603
2002-07-17 08:11:21
如题?
...全文
87
5
打赏
收藏
新手问题之五:JAVA中怎样调用WINDOWS的DLL中的函数?
如题?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
sunpengjie
2002-07-17
打赏
举报
回复
其实java调用dll是和c分不开的,下面给出一个java调用windows中dll的函数的例子。程序如下
hellodll.java
public class hellodll
{
static
{
System.loadLibrary("sunpengjie");
}
public native static String helloget();
public native static void helloset(int helloword);
public static void main(String[] args)
{
hellodll hello = new hellodll();
hello.helloset(1);
System.out.println(hello.helloget());
}
}
用javac hellodll.java编译它,会生成hellodll.class
再用javah hellodll,则会在当前目录下生成hellodll.h
hellodll.cpp文件
#include "hellodll.h"
String str = "";
//在产生的hellodll.h中会看到两个函数的原型
JNIEXPORT ? JNICALL Java_hellodll_helloget (JNIEnv *, jclass)
{
return str;
}
JNIEXPORT void JNICALL Java_hellodll_helloset (JNIEnv *, jclass, jint j)
{
if (j>0)
{ str = "This is a helloword Program!!!!!!" ;}
if(j<=0)
{ str = "This is not a helloword Program!!!!!!";}
}
编译连接成库文件,在WINDOWS下生成sunpengjie.dll。把sunpengjie.dll拷贝到hellodll.class的目录下,java hellodll就可以运行了。
lexus
2002-07-17
打赏
举报
回复
http://www.csdn.net/Expert/TopicView1.asp?id=879129
lwg7603
2002-07-17
打赏
举报
回复
能给一个详细的例子吗??
G-old
2002-07-17
打赏
举报
回复
System.loadLibrary("Library DLL Name");
public native void method();
javapro
2002-07-17
打赏
举报
回复
Thinking in java: JNI
HEX / RGB 颜色转换工具
颜色转换工具
组合式专用铣齿机床设计(论文 CAD图纸).rar
组合式专用铣齿机床设计(论文 CAD图纸).rar
AI Challenger 2018 阅读理解赛道代码分享.zip
一款 AI 辅助阅读器,三栏设计实现笔记、阅读、对话同屏交互,让深度阅读更高效
易语言源码多任务同时下载源码
易语言源码多任务同时下载源码
Artix-7-XC7A35T-DDR3开发板硬件参考设计资料
源码下载地址: https://pan.quark.cn/s/3a6709c3f9be This is a TPYboard You can get started right away by writing your Python code in 'main.py'. For a serial prompt: -
Windows
: you need to go to 'Device manager', right click on the unknown device, then update the driver software, using the 'tpybcdc.inf' file found on this drive. Then use a terminal program like Hyperterminal or putty. - Mac OS X: use the command: screen /dev/tty.usbmodem* - Linux: use the command: screen /dev/ttyACM0 Please visit http://www.tpyboard.com/help/ for further help. Designed by TurnipSmart in Shandong!
Java SE
62,622
社区成员
307,257
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章