Java 调用 dll 字符串返回类型方法
Java calling dll String return type method
我正在尝试通过JAVA应用程序调用DLL文件中的函数。 我发现这个来源 http://blog.mwrobel.eu/how-to-call-dll-methods-from-java/,一切都像魅力一样工作。
但是,我想对 DLL 文件进行一些修改,我希望函数从源返回字符串而不是 char。
这是我的Java代码。
public class Main {
public interface simpleDLL extends Library {
simpleDLL INSTANCE = (simpleDLL) Native.loadLibrary("simpleDLL", simpleDLL.class);
int giveIntGetInt(int a); // int giveIntGetInt(int a);
}
public static void main(String[] args) {
simpleDLL sdll = simpleDLL.INSTANCE;
String result = sdll.giveCharGetChar("abc");
System.out.println("result: " + result);
int a = 3;
int result1 = sdll.giveIntGetInt(a); // calling function with int parameter&result
System.out.println("giveIntGetInt("+a+"): " + result1);
}
}
这是我C++代码。
#include "simpleDLL.h"
#include <string>
#include <stdexcept>
using namespace std;
using std::string;
namespace simpleDLLNS
{
string simpleDLL::giveCharGetChar(string a)
{
return "abc";
}
int simpleDLL::giveIntGetInt(int a)
{
return 3*a;
}
void simpleDLL::simpleCall(void)
{
int x = 3;
return;
}
int simpleDLL::giveVoidPtrGetInt(void* param)
{
if(param!=0)
{
int* x = (int*)param;
return *x;
}
else
{
return -1;
}
}
}
除此之外,如果我将字符串更改为字符,它会返回韩语单词。如果我使用的是字符串,Java将遇到错误。请帮忙。
有关如何使用 Java 中的 JNA 将字符串发送到 C 库并从 C 库接收字符串的示例:
http://www.eshayne.com/jnaex/index.html?example=2
相关文章:
- QtQuick - qml:28:错误:未知方法返回类型:自定义类型
- C++方法是否可以根据传递给构造函数的参数具有不同的返回类型?
- 具有引用返回类型的重写方法上的协变返回类型无效
- Java 调用 dll 字符串返回类型方法
- 必须使用尾随返回类型的示例,因为无法用旧方法解决问题
- 如何拥有两个名称相同但返回类型不同的纯虚拟方法
- qml 未知方法返回类型:ArchiveFile*,即使调用了 qmlRegisterUncreatableType
- std::d eclval vs crtp,无法从不完整类型推断方法返回类型
- 将返回类型推断为模板参数类型方法
- dlsym() 解决方法返回类型
- 我如何根据某些模板参数影响模板类方法的返回类型
- 访问方法的返回类型
- 更改基类方法在其派生类中的返回类型
- 具有协变返回类型的方法在 VC++ 上崩溃
- 如何检查模板类方法返回类型
- 如何使用类型专用化模板方法,该类型本身就是一个模板,其中只有返回类型依赖于模板类型
- 解释C 中三种返回类型的方法
- 覆盖方法返回类型,在C 中使用不完整的派生类
- 存储方法的返回类型和参数类型
- C 多重继承,虚拟方法覆盖问题和协变量返回类型