java调用vsdll,从java代码调用VS6 C DLL函数

i make a simple c function in Visual studio 6 this is the code#include"stdafx.h"BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)

{

return TRUE;

}

extern "C" __declspec(dllexport) char __stdcall GetCompanyCode()

{

return 1;

}

i need to call the function GetCompanyCode from java so i used JNA at first i create Interface in java

package javaapplication4;

import com.sun.jna.Library;

/**

*

* @author amir

*/

public interface CompanyCode extends Library

{

public byte GetCompanyCode();

}

then load the dll

import java.io.FileNotFoundException;

import java.io.IOException;

import com.sun.jna.Native;

import java.security.NoSuchAlgorithmException;

import java.sql.SQLException;

/**

*

* @author amir

*/

public class JavaApplication4

{

/**

* @param args the command line arguments

*/

public static void main(String[] args) throws IOException, FileNotFoundException, NoSuchAlgorithmException

{

System.setProperty("jna.library.path", "C:/");

CompanyCode Company= (CompanyCode)Native.loadLibrary("CompanyCode", CompanyCode.class);

byte x=Company.GetCompanyCode();

System.out.println(x);

}

}

i got the error

Quote:Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'GetCompanyCode': The specified procedure could not be found.

at com.sun.jna.Function.(Function.java:179) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:347) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:327) at com.sun.jna.Library$Handler.invoke(Library.java:203) at com.sun.proxy.$Proxy0.GetCompanyCode(Unknown Source) at javaapplication4.JavaApplication4.main(JavaApplication4.java:28) C:\Users\amir\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)

what should i do?

What I have tried:

now i don't know what else i should do, i googled lot but what i found i already did

解决方案

Handler.invoke(Library.java:203) at com.sun.proxy.

Proxy0.GetCompanyCode(Unknown Source) at javaapplication4.JavaApplication4.main(JavaApplication4.java:28) C:\Users\amir\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)

what should i do?

What I have tried:

now i don't know what else i should do, i googled lot but what i found i already did

You must carefully read and understand the error message. Here is "Error looking up function 'GetCompanyCode': The specified procedure could not be found."

So the linker says that dll is found but the function not. Check with the good olddepedency walker that the function name is properly exported. My guess is that the __stdcall makes some changes in the so called decorated name.

And I would export an int as result, because it is native data type.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值