如何远程加载dll库?

编程入门 行业动态 更新时间:2024-10-25 01:34:12
本文介绍了如何远程加载dll库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一台安装了应用程序的远程计算机,它的C语言编写的API被编译成dll.

I have a remote machine which has an application installed and has its APIs written in C compiled into a dll.

我想使用通过在Java中通过JNA远程加载dll公开的API与应用程序进行交互.也就是说,我的客户端代码需要将dll加载到目标计算机中并与应用程序进行交互.

I want to interact with the application using the APIs exposed by loading the dll through JNA in java remotely. i.e., my client code need to load the dll in the target machine and interact with the application.

我探索了使用JMI的可能性,但它增加了更多的复杂性.

I explored the possibility of using JMI, but it adds more complexity.

如何使用JNA/JNI远程加载dll文件?

How to load dll files remotely using JNA/JNI?

推荐答案

您可以相应地指定dll的位置.我正在一个需要类似功能的项目中.请参考下面的代码.与客户端共享目标计算机中dll的位置后,您可以通过指定如下所示的路径来访问dll.

You can specify the location of the dll accordingly. I'm working on a project which requires similar features. Refer the code below . Once you shared the location of the dll in the target machine with your client , you can access the dll by specifying the path as shown below.

public class TestRemoteDll{ public native String readFile(); public static void main(String args[]){ System.load("\\\\{Device's Name}\\Users\\Milan.AF\\Desktop\\RemoteDir\\Remotedll.dll"); TestRemoteDll test = new TestRemoteDll(); System.out.println("Calling native method!"); String sum = test.readFile(); System.out.println("Returned from Native Method"); System.out.println(sum); }

}

并确保也相应地创建了dll(使用的dll文件也应与客户端共享).创建dll时,必须以类似的方式指定文件的位置,如下所示. /p>

And make sure you create the dll accordingly as well(The files dll use should be shared with the client as well ).You have to specify the location of files in a similar way when you create a dll as shown below.

#include "stdafx.h" #include "iostream" #include<string> #include <fstream> #include "Remotedll.h" using namespace std; string RemoteDll::readFile() { int sum=0,x; ifstream inFile; inFile.open("\\\\{Device's Name}\\temp\\intSum.txt"); if (!inFile) { return "Failed to open file!"; } while (inFile >> x) { sum = sum + x; } inFile.close(); string str = to_string(sum); return "File operation successful! Sum =" + str ;

}

我希望这会有所帮助.

更多推荐

如何远程加载dll库?

本文发布于:2023-11-12 07:21:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580868.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   dll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!