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.