主页>技术社区>编程问答

无法使用JNA

eIT.com.cn 2023/3/11 8:27:15 阅读 6 次

打印


如何解决无法使用JNA?

我已经使用plugin.py从pythoncffi创建了DLL(如下所示)。我试图使用JNA从Javado_stuff(),但是出现了类似“my_plugin.do_stuff()的,但是初始化失败。返回0。”它不是在dll中存在的python。

我试图使用JNAWindows现有的Kernel32.dll,并且该正常工作,所以我不确定Windows dll与我创建的DLL有什么区别。

:plugin.py

import cffi
ffibuilder = cffi.FFI()
ffibuilder.emding_api("""   int do_stuff(int,int);
""")
ffibuilder.set_source("my_plugin","")
ffibuilder.emding_init_code("""   from my_plugin import ffi
   @ffi.def_extern()   def do_stuff(x,y):       print("adding %d and %d" % (x,y))       return x + y
""")
ffibuilder.compile(target="My-1.5.*",verbose=True)

如果我们在python plugin.pypip的依赖关系后使用命令cffi运行,您将在当前目录中获得my_plugin.cMy-1.5.dll

Java My-1.5.dll

public class PythonToJavaDll {   public interface NativeInterface extends Library {       int do_stuff(int x,int y);   }   public static void main(String[] args) {       Sy.out.println("Native Library started");       NativeInterface nativeExample = (NativeInterface)Native.loadLibrary("My-1.5",NativeInterface.class);       int value = nativeExample.do_stuff(3,4);       Sy.out.println("String value:"+value);   }
}

Native Library started
function my_plugin.do_stuff() called,but initialization code .  
Returning 0.
String value:0

但是,当我运行现有的C:/windows/Sy32/kernel32.dll时,我便可以DLL的。

public class BeepExampl {   public interface Kernel32 extends Library {       // FREQUENCY is ex in hertz and ranges from 37 to 32767       // DURATION is ex in milliseconds       public boolean Beep(int FREQUENCY,int DURATION);       public void Sleep(int DURATION);   }   public static void main(String[] args) {       Sy.out.println("Native Library started");       Kernel32 lib = Native.loadLibrary("kernel32",Kernel32.class);       Sy.out.println("Native Lib:" + lib);       lib.Beep(698,500);       Sy.out.println("Sleep Started:" + new Date());       lib.Sleep(500);       Sy.out.println("Sleep End:" + new Date());   }
}

Native Library started
Native Lib:Proxy interface to Native Library <kernel32.dll@140715486085120>
Sleep Started:Fri Aug 14 21:16:48 IST 2020
Sleep End:Fri Aug 14 21:16:48 IST 2020
Native Lib:Proxy interface to Native Library <kernel32.dll@140715486085120>

有人可以帮助使用Java(JNA)Java中的Python DLL吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)






相关内容


热门栏目


特别声明


最新资讯
热讯排行



合作媒体友情链接
生活常识小贴士 软件开发教程 智慧城市生活网 息县通生活服务[移动版] 息县商圈[移动版] 美食菜谱
健康养生 法律知识 科技频道 电影影讯 留学考研学习 星座生肖|解梦说梦




关于我们 | 联系我们 | 合作媒体 | 使用条款 | 隐私权声明 | 版权声明

      Copyright © 2023 eIT.com.cn. All Rights Reserved. 豫ICP备2022012332号