Click here to Skip to main content
13,666,077 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
Posted 23-Apr-17 23:19pm
Updated 23-Apr-17 23:41pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180810.1 | Last Updated 24 Apr 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100