Java - C# interop

Discussion in 'Java' started by SirThanxALot, Feb 7, 2005.

  1. SirThanxALot

    SirThanxALot Guest

    Is there a way for interop between C# and Java?
    Is it possible to use the JNI with C#
    Or do I have to do a workaround with (V)C++?

    thanx
    srtnaxalt
    SirThanxALot, Feb 7, 2005
    #1
    1. Advertising

  2. SirThanxALot wrote:

    > Is there a way for interop between C# and Java?


    JAVA IN C# 1. You can register your Java classes as COM
    objects using the ActiveX Bridge in the JDK and then use COM
    InterOp.

    JAVA IN C# 2. Use P/Invoke to use the JNI invocation API and
    System.Reflection.Emit to call the native JNI funtions in
    the JNIEnv structure. This is a hack, it's difficult and
    practically undocumented.

    C# IN JAVA. You can write a JNI DLL in C# by using
    System.Reflection.Emit to call the native JNI funtions in
    the JNIEnv structure and then usng ILDasm and ILAsm to
    create exported JNI functions from the C# DLL. This is a
    hack, it's difficult and practically undocumented.

    > Is it possible to use the JNI with C#
    > Or do I have to do a workaround with (V)C++?


    Using mC++ is a lot easier. You can think of creating a JNI
    wrapper in mC++ instead of writing it all in mC++.

    There are a couple of Java/.NET interop libraries somewhere
    on the web.

    You can also just create the Java part and the .NET part in
    2 separate processes and then use socket streams to make
    them communicate.


    --

    // Alessandro Angeli
    // MVP :: Digital Media
    // a dot angeli at psynet dot net
    Alessandro Angeli [MVP::DigitalMedia], Feb 7, 2005
    #2
    1. Advertising

  3. SirThanxALot wrote:
    > Is there a way for interop between C# and Java?
    > Is it possible to use the JNI with C#
    > Or do I have to do a workaround with (V)C++?
    >
    > thanx
    > srtnaxalt


    Java (via JNI) can interop with C, and C can interop with C++.
    So it comes down to the question: Can C# interop with C or C++ ?


    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
    Thomas Fritsch, Feb 7, 2005
    #3
  4. SirThanxALot

    SirThanxALot Guest

    Thanx for the most informing reply.
    So now it comes down to this:

    I need to the C# in Java thingy.
    For now, I see the JNI dll writing in C# as a last resort.
    I'd better make a VC++ wrapper/bridge

    something like
    java <-1-> jni <-2-> c++ <-3-> C#
    parts 1 and 2 are ok for me
    3 remains an issue as Thomas Fritsch stated

    I just want to do this. Ihave made a class in C#
    I want to create an instance of it (from within C++) and invoke
    methods on it.

    Thanx,
    srtnxalt


    Alessandro Angeli [MVP::DigitalMedia] wrote:
    > SirThanxALot wrote:
    >
    >
    >>Is there a way for interop between C# and Java?

    >
    >
    > JAVA IN C# 1. You can register your Java classes as COM
    > objects using the ActiveX Bridge in the JDK and then use COM
    > InterOp.
    >
    > JAVA IN C# 2. Use P/Invoke to use the JNI invocation API and
    > System.Reflection.Emit to call the native JNI funtions in
    > the JNIEnv structure. This is a hack, it's difficult and
    > practically undocumented.
    >
    > C# IN JAVA. You can write a JNI DLL in C# by using
    > System.Reflection.Emit to call the native JNI funtions in
    > the JNIEnv structure and then usng ILDasm and ILAsm to
    > create exported JNI functions from the C# DLL. This is a
    > hack, it's difficult and practically undocumented.
    >
    >
    >>Is it possible to use the JNI with C#
    >>Or do I have to do a workaround with (V)C++?

    >
    >
    > Using mC++ is a lot easier. You can think of creating a JNI
    > wrapper in mC++ instead of writing it all in mC++.
    >
    > There are a couple of Java/.NET interop libraries somewhere
    > on the web.
    >
    > You can also just create the Java part and the .NET part in
    > 2 separate processes and then use socket streams to make
    > them communicate.
    >
    >
    SirThanxALot, Feb 8, 2005
    #4
  5. SirThanxALot wrote:

    > I just want to do this. Ihave made a class in C#
    > I want to create an instance of it (from within C++) and
    > invoke methods on it.


    You need to use the managed C++ extension in VC7.x (mC++,
    for brevity). Compile your C# code into a DLL assembly,
    reference the types in this assembly from mC++ and compile
    your mC++ into a DLL assembly as well (/clr switch), but
    include the native JNI code (mC++ can mix managed and native
    code). I think you can also compile your C# into a module
    and link this module inside the mC++ DLL, but I never tried.


    --

    // Alessandro Angeli
    // MVP :: Digital Media
    // a dot angeli at psynet dot net
    Alessandro Angeli [MVP::DigitalMedia], Feb 8, 2005
    #5
  6. SirThanxALot

    dc Guest

    What are you really trying to do?

    There are a zillion ways to do interop between Java and C#. You can break
    them down into categories:
    1- in process
    2- out of process, directo communications
    3- shared resource

    For inprocess, you can do it the way Mr Agneli has described. It's a bit
    messy. There are other options.

    for example
    Have you seen IKVM? It is a JVM written implemented on top of the CLR.
    What this means is you can take any Java class and run it in a .NET
    container.
    Some other neat possibilities like, producing Java "stubs" for .NET class
    libraries , and then being able to call them from Java code.

    www.ikvm.net

    For out-of-process, there you are talking about webservices, SOAP, socket
    comms.

    For shared resource, maybe both the Java app and the C# app read and write
    the same file, or queue, or database.

    Which way you choose depends on the requirements of your situation.


    -Dino
    http://blogs.msdn.com/DotNetInterop



    "SirThanxALot" <> wrote in message
    news:...
    > Thanx for the most informing reply.
    > So now it comes down to this:
    >
    > I need to the C# in Java thingy.
    > For now, I see the JNI dll writing in C# as a last resort.
    > I'd better make a VC++ wrapper/bridge
    >
    > something like
    > java <-1-> jni <-2-> c++ <-3-> C#
    > parts 1 and 2 are ok for me
    > 3 remains an issue as Thomas Fritsch stated
    >
    > I just want to do this. Ihave made a class in C#
    > I want to create an instance of it (from within C++) and invoke
    > methods on it.
    >
    > Thanx,
    > srtnxalt
    >
    >
    > Alessandro Angeli [MVP::DigitalMedia] wrote:
    >> SirThanxALot wrote:
    >>
    >>
    >>>Is there a way for interop between C# and Java?

    >>
    >>
    >> JAVA IN C# 1. You can register your Java classes as COM
    >> objects using the ActiveX Bridge in the JDK and then use COM
    >> InterOp.
    >>
    >> JAVA IN C# 2. Use P/Invoke to use the JNI invocation API and
    >> System.Reflection.Emit to call the native JNI funtions in
    >> the JNIEnv structure. This is a hack, it's difficult and
    >> practically undocumented.
    >>
    >> C# IN JAVA. You can write a JNI DLL in C# by using
    >> System.Reflection.Emit to call the native JNI funtions in
    >> the JNIEnv structure and then usng ILDasm and ILAsm to
    >> create exported JNI functions from the C# DLL. This is a
    >> hack, it's difficult and practically undocumented.
    >>
    >>
    >>>Is it possible to use the JNI with C#
    >>>Or do I have to do a workaround with (V)C++?

    >>
    >>
    >> Using mC++ is a lot easier. You can think of creating a JNI
    >> wrapper in mC++ instead of writing it all in mC++.
    >>
    >> There are a couple of Java/.NET interop libraries somewhere
    >> on the web.
    >>
    >> You can also just create the Java part and the .NET part in
    >> 2 separate processes and then use socket streams to make
    >> them communicate.
    >>
    dc, Feb 11, 2005
    #6
  7. SirThanxALot

    sindy55

    Joined:
    Aug 11, 2009
    Messages:
    1
    Interop between Java and C#

    You may try CSharpJavaMerger to see if it can meet your needs. It is an open source tool.

    Thanks.
    sindy55, Aug 11, 2009
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brett Roy

    Tab Fails on TextBox using COM Interop

    Brett Roy, Sep 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    427
    Brett Roy
    Sep 29, 2003
  2. JerryP

    com interop C# VB6

    JerryP, Oct 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    608
    JerryP
    Oct 28, 2004
  3. Kevin Burton

    Web service and Java interop.

    Kevin Burton, Feb 18, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    96
    Dino Chiesa [Microsoft]
    Feb 24, 2004
  4. Raj

    WS - .Net to Java interop

    Raj, Jan 30, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    135
  5. VK

    Javascript <=> Java interop

    VK, Mar 5, 2011, in forum: Javascript
    Replies:
    0
    Views:
    158
Loading...

Share This Page