I try to use a .NET Library in Java. Therefore, I use JNI calls of a C++ project which refers / uses a DLL of the .NET.
To use the .NET Library I have several steps in-between. First I use C# project as a ‘wrapper’ instance between the Library and a C++ project. The C# project creates a DLL.
The main wrapper C# class (CSHARPWRAPPERSession) is [ComVisible(true)] and has a fixed GUID [Guid("XXX")]
Out of this ‘C#’-DLL I create a TLB file.
This tlb file is imported by my C++ project.
#import ".\CSHARPWRAPPER.NET.tlb" no_namespace, named_guids
When I create an exe out of the C++ project I can use the wrapper perfectly and call the needed .NET library.
Now I try to make a connection between the C++ project an JAVA. Therefore, I use JNI and created DLL out of the C++.
This leads to the error 0x80040154 – Class not registered.
This error happens, when I try to call CoCreateInstance(CLSID_CSHARPWRAPPERSession)
I have registered all used Libraries with regasm and done a gacutil on it.
What am I doing wrong? Any ideas or suggestions?
Related
I am making a android project with some native code . running javah results in header files which contain function prototypes with fully qualified java class name in their names. I assume this means that those functions and headers are generated to be called only by the java class which was used to create them using javah.
How do I go on making a native lib that I can use with other classes as well as other projects. Like say I made a library that has a function that I want to use in all my projects then how would I build it so that I can use just the .so file each time without recompiling it for the project. I think we call this dynamic library?
Is it possible? or do I have to create seperate jni headers for each class and then reuse the remaining c/c++ code?
if you want to reuse your native library from various Java projects, you should directly bundle your native library with a Java class that is independent from your initial project.
This way you'll be able to distribute it as an Android Library Project, and use it from your various classes and projects.
I am working on a project in which I need to create a java wrapper class to call external functions of an un-managed c dll using SWIG.
The tutorials on SWIG main site and other resources out there always need the implementing c source files and the header files.
Is there a way to reference the dll to SWIG and create the Java wrapper, and if there isn't, is there another approach to achieve my goal.
Thanks.
I have an existing .c and .h file from a library. I would like to be able to call the functions contained within the c files from Java. I understand that this requires the JNI, and I have a pretty good understanding of how I will need to modify the .c and .h files in order to make them work with the JNI. What I don't fully understand how to do, or if it's even the purpose of the JNI, is to make a simple JNI library that I can then wrap into another java application. I want to create the interface; extend the C API into Java so I can use it there. The final result would be something like: someCmethodInSomeJNILibrary() located in some jnilib sort of file.
Thanks in advance
First, you may wish to consider using JNA. JNA would allow you to interact without writing additional native code. This is particularly convenient if you already have a library and don't want to build another.
With JNI, the steps required include:
Design a Java API of native methods for interacting with the C code.
Use javah to generate C stubs for the Java native methods.
Glue the C stubs to your C code.
Generate a dynamic/shared library containing the native method functions and your original C code.
Load that shared library in Java.
More detail can be found in "Compiling, Loading, and Linking Native Methods" in the JNI documentation.
I have dll file which is controlling a device, I need a tool to generate java classes which take the dll file as an input and generate all the need JNI classes.
Note: I don't have the C,C++ code for that DLL.
I believe you are doing all this so that you can call C++ methods through Java.
Instead use JNA library. It does not require any explicit JNI classes to be built. You can directly call C++methods. Read more about it here
Problem Description
I'm writing module for Android (JAVA) that use native code (C). In JAVA I have created Class "MyClass.java" and implement all functions and classes there, also I call loadLibrary function from that file.
Now I want to build something like dll in C only for Android JAVA in order to give it to other users and they can use my class and functions.
You probably want to create a library project that contains your Java and C stuff.
http://developer.android.com/guide/developing/projects/index.html#LibraryProjects
Do you want it to be used at runtime or compile time?