0

我必须将本机 C++ 库映射到 JNA,这是库头:

#ifndef WORMDLL_H
#define WORMDLL_H

#pragma once


#ifdef WORMDLL_EXPORTS
#define WORMDLL_API __declspec(dllexport) 
#else
#define WORMDLL_API __declspec(dllimport) 
#endif

#include "wormError.h"

typedef BYTE WORM_DATA;

WORMDLL_API WORM_ERROR  worm_readData(const char* mountPoint, WORM_DATA *data,const unsigned int offset,const unsigned int numBlocks);
#endif 

这是我用 JNAeator 制作的映射:

package test;
import com.ochafik.lang.jnaerator.runtime.LibraryExtractor;
import com.ochafik.lang.jnaerator.runtime.MangledFunctionMapper;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import com.sun.jna.Pointer;
import com.sun.jna.PointerType;
import java.nio.ByteBuffer;

public interface TestLibrary extends Library {
    public static final String JNA_LIBRARY_NAME = LibraryExtractor.getLibraryPath("test", true, TestLibrary.class);
    public static final NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance(TestLibrary.JNA_LIBRARY_NAME, MangledFunctionMapper.DEFAULT_OPTIONS);
    public static final TestLibrary INSTANCE = (TestLibrary)Native.loadLibrary(TestLibrary.JNA_LIBRARY_NAME, TestLibrary.class, MangledFunctionMapper.DEFAULT_OPTIONS);


    TestLibrary.WORM_ERROR worm_readData(String mountPoint, ByteBuffer data, int offset, int numBlocks);

    public static class WORM_ERROR extends PointerType {
        public WORM_ERROR(Pointer address) {
            super(address);
        }
        public WORM_ERROR() {
            super();
        }
    };
}

这是 DependencyWalker 找到的导出函数:

(装饰) 在此处输入图像描述 (未装饰) 在此处输入图像描述

当我尝试使用此配置运行测试时,我得到:

线程“主”java.lang.UnsatisfiedLinkError 中的异常:查找函数“worm_readData”时出错

为什么 JNA 找不到函数名称?

4

0 回答 0