java and C# dll

  • Thread starter Thread starter Guest
  • Start date Start date
...
Does anyone know how to load C# dll (or .NET dll) in Java?

This is not one of the easiest tasks to do...

It incorporates the use of several layers, but very simplified it can look
like this:

1. Create JNI-headers in C/C++ for native methods in Java

To make a native dll to be invoked when a specific (native) Java-method is
to be called, you must write JNI in C or C++. The specially generated
headers can't be changed, as they must conform to the Java method-call.

2. Use the JNI-headers to create a dll in C++ "managed code", wrapping
"unmanaged code" from .NET (e.g. C#).

This is really the tricky part. Most .NET-dlls can be exposed as COM, and
can hence be called from a wrapper in unmanaged C++.

This is just a simple explanation on how it has to be done, but yes, it is
doable...

// Bjorn A
 
The solution that you suggested is in "managed" C++, not in C#, so I assume that there's no way C# dll can be loaded in Java only managed C++ dll, correct?


----- Bjorn Abelli wrote: -----


...
Does anyone know how to load C# dll (or .NET dll) in Java?

This is not one of the easiest tasks to do...

It incorporates the use of several layers, but very simplified it can look
like this:

1. Create JNI-headers in C/C++ for native methods in Java

To make a native dll to be invoked when a specific (native) Java-method is
to be called, you must write JNI in C or C++. The specially generated
headers can't be changed, as they must conform to the Java method-call.

2. Use the JNI-headers to create a dll in C++ "managed code", wrapping
"unmanaged code" from .NET (e.g. C#).

This is really the tricky part. Most .NET-dlls can be exposed as COM, and
can hence be called from a wrapper in unmanaged C++.

This is just a simple explanation on how it has to be done, but yes, it is
doable...

// Bjorn A
 
The solution that you suggested is in "managed" C++,
not in C#, so I assume that there's no way C# dll can
be loaded in Java only managed C++ dll, correct?

I see now that I wrote point 2 the "wrong way around", I meant "unmanaged
C++", but I'll try to explain it in another way.

A dll created from C# only can't be called *directly* from Java.

To use it from Java, you need to "wrap" it by creating another DLL calling
the C#-dll, where the outermost layer is *unmanaged* code in C++, as a JNI
must be written in C or C++.

I hope I made it clearer this time... :-)

// Bjorn A
 
Ah... clear now

1. Using JNI to create the C/C++ header file.
2. Implement "unmanaged" C/C++ -the wrapper- to call C# dll

I wonder how the performance would be (slow or just OK)

Thanks,
-C

----- Bjorn Abelli wrote: ----

not in C#, so I assume that there's no way C# dll ca
be loaded in Java only managed C++ dll, correct

I see now that I wrote point 2 the "wrong way around", I meant "unmanage
C++", but I'll try to explain it in another way

A dll created from C# only can't be called *directly* from Java

To use it from Java, you need to "wrap" it by creating another DLL callin
the C#-dll, where the outermost layer is *unmanaged* code in C++, as a JN
must be written in C or C++

I hope I made it clearer this time... :-

// Bjorn
 
"Ching-Lung" ...
I wonder how the performance would be (slow or just OK)?

Whether the performance is too slow or not can only be judged by the users'
perception of the execution time, but it's nothing I would recommend other
than as an emergency solution, as it involves the execution of two virtual
machines (the JVM and the CLR).

// Bjorn A
 
Fair enough, thanks a bunch

-C


----- Bjorn Abelli wrote: ----

"Ching-Lung" ..
I wonder how the performance would be (slow or just OK)

Whether the performance is too slow or not can only be judged by the users
perception of the execution time, but it's nothing I would recommend othe
than as an emergency solution, as it involves the execution of two virtua
machines (the JVM and the CLR)

// Bjorn
 
Back
Top