Using Java from .Net (C#) with JNI

K

kent

Hello

I have a java class and I want to call it from a .Net project (in C#).

What I have done for now:
- I have written C++ code (by using Visual Studio 6.0) to call the java
class by using the JNI: this is working. This code has been included in a
dll.
- When I am calling the dll from a .Net project, the following exception is
raised "Object not set to an instance of an object"

When I call this DLL from an executable written in C++ (built with Visual
Studio 6): it is working.
When I call another DLL (which does not use JNI) from the .Net project it is
also working.

The problem comes from running the JNI in .Net.


I finally found that the JNI function JNI_CreateJavaVM (for initializing
the JVM and the environment) returns null objects (instead of initialized
pointers to the JVM and to the environment) when the DLL is called from a
..Net project.


Does anybody know why the JVM is not correctly initialized when the DLL is
called from .Net code ? What can I do to make it work ? (probably by
modifying the init arguments passed to the JNI_CreateJavaVM function ??)


Thank you for your help
 
J

Jacky Kwok

kent said:
Hello

I have a java class and I want to call it from a .Net project (in C#).

What I have done for now:
- I have written C++ code (by using Visual Studio 6.0) to call the java
class by using the JNI: this is working. This code has been included in a
dll.
- When I am calling the dll from a .Net project, the following exception is
raised "Object not set to an instance of an object"

When I call this DLL from an executable written in C++ (built with Visual
Studio 6): it is working.
When I call another DLL (which does not use JNI) from the .Net project it is
also working.

The problem comes from running the JNI in .Net.


I finally found that the JNI function JNI_CreateJavaVM (for initializing
the JVM and the environment) returns null objects (instead of initialized
pointers to the JVM and to the environment) when the DLL is called from a
.Net project.


Does anybody know why the JVM is not correctly initialized when the DLL is
called from .Net code ? What can I do to make it work ? (probably by
modifying the init arguments passed to the JNI_CreateJavaVM function ??)


Thank you for your help

I do not know what is the problem in your case.

However, C# call to JNI is OK in my experience. In my case, C# program
calls to a managed C++ class object which calls into the JNI.

I think you can check:

1. double confirm the parameters are correct when call CreateJavaVM .
2. confirm the PATH environment variable is correct to point to the PATH
of "jvm.dll".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top