Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i make a simple c function in Visual studio 6 this is the code
C++
#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
Java
package javaapplication4;
import com.sun.jna.Library;
/**
 *
 * @author amir
 */
public interface CompanyCode extends Library
{
    public  byte GetCompanyCode();
}

then load the dll
Java
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
Posted
Updated 23-Apr-17 23:41pm

1 solution

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.
 
Share this answer
 
Comments
amir tarek 24-Apr-17 5:47am    
i tried dependency walker and the function name is _GetCompanyCode@0 so how i convert the name to GetCompanyCode?
amir tarek 24-Apr-17 6:00am    
i solved it i user StdCallFunctionMapper to change the name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900