有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java与JC++第三头C++文件头的连接

我有一个第三方dll文件,其标题如下

class MyClass
{
public:

    MyClass() {};
    virtual ~MyClass() {};
    int Double(int x);
};

我无法使用JNA连接dll文件(因为我无法在这里进行外部连接)。所以我创建了一个包装器dll。从那个包装器dll,我试图连接到第三方dll。包装器dll头文件(Sample.h)

extern "C" {
int __declspec(dllexport) Double(int x);
}

包装dll的cpp文件

typedef int (__cdecl *MYPROC)(int); 
int func(int x)
{
HINSTANCE hinstLib; 
MYPROC ProcAdd; 
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
int result;

printf("inside the function");
// Get a handle to the DLL module.

hinstLib = LoadLibrary(TEXT("example_dll.dll")); 

// If the handle is valid, try to get the function address.

if (hinstLib != NULL) 
{ 
    ProcAdd = (MYPROC) GetProcAddress(hinstLib, "Double"); 

    // If the function address is valid, call the function.

    if (NULL != ProcAdd) 
    {
        fRunTimeLinkSuccess = TRUE;
        result = ProcAdd(x);
        printf("Result: %d", result);
    } else {
        printf("function not found");
    }
    // Free the DLL module.

    fFreeResult = FreeLibrary(hinstLib); 
} 

// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess) 
    printf("Message printed from executable\n"); 

return result; 
}

使用C程序(由g++编译),我可以连接dll并获取数据

但是通过Java程序(使用JNA),我可以连接第一个dll,但是第一个dll不能连接第二个dll

谁能告诉我怎么解决这个问题吗?当然,如果有其他方法来解决它


共 (0) 个答案