c - How to use a dll file in java code using JNA? -
i have use dll file (of c code) in java code, searched allot , found jna suitable way it. therefore, trying write helloworld program using jna-4.1.0.jar. below c code:
//c hello world example #include <stdio.h> void __declspec(dllexport) _stdcall hellofromc() { printf("hello world c code! \n"); }
and make dll c code using following commands on cmd:
gcc -c ctest.c gcc -shared -0 test.dll ctest.o
running these commands gives me dll c code, place @ root of simple java project.
now here java class:
import com.sun.jna.native; import com.sun.jna.library; public class helloworld { public interface ctest extends library { void hellofromc(); } public static void main(string[] args) { ctest instance = (ctest) native.loadlibrary("ctest", ctest.class); instance.hellofromc(); } }
now when run java program on eclipse, getting error:
exception in thread "main" java.lang.unsatisfiedlinkerror: %1 not valid win32 application.
kindly me solve issue has taken of time!
gcc -c ctest.c gcc -shared -o test.dll ctest.o try 'o' ^ not '0'
it's finding dll doesn't it.
Comments
Post a Comment