• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Java to call C# method

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure which topic to put this in, but here goes....

I need to call a method in C# from within a java app. I don't want to use webservices or anything like that. I want to compile the C# intoa dll and be able to call that somehow from the Java app.

Can this be done? From my understanding I have to use c++ as the middleman. If this can be done, can someone recommend an exmaple or website on how to do this.

Many thanks in advance....
 
Marshal
Posts: 82459
594
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds like something which can be done, yes. Don't know much about it, and other people probably know lots about it, but have a look in the JNI and see whether that helps.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AFAIK, it can't be done directly, and you will indeed need to go through a C++ wrapper. See http://faq.javaranch.com/java/JavaIntermediateFaq#callingCom for some more detail.
 
author
Posts: 23965
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's actually not that bad -- as you need to write the c++ wrapper anyway, even to call a C/C++ library, just for the JNI calling convention. This is another step, but it is possible to have the managed C++ (.NET) code and the C++ code for JNI in the same file.

Henry
 
Frankey James
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Awesome. Thanks for the responses, everyone. I'm not going to start this for a few weeks, but I'll take a look at the recommendations and will be back if I have issues. ;-)
reply
    Bookmark Topic Watch Topic
  • New Topic