2 Replies - 555 Views - Last Post: 27 July 2010 - 06:28 AM Rate Topic: -----

#1 mohan1234512345  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-July 10

calling c++ code from java

Posted 27 July 2010 - 12:43 AM

I wrote a function to access a printer in c++, how can i call that method from java.
Is This A Good Question/Topic? 0
  • +

Replies To: calling c++ code from java

#2 aniri  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 54
  • View blog
  • Posts: 657
  • Joined: 24-November 09

Re: calling c++ code from java

Posted 27 July 2010 - 12:48 AM

This article might prove useful.

Also, you could try finding a similar method in java. It might be easier than importing the c++ code. I don't how complicated your method is though..
Was This Post Helpful? 0
  • +
  • -

#3 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: calling c++ code from java

Posted 27 July 2010 - 06:28 AM

:) that article is backwards "How to Call Java functions from C" --but the last part is the ticket JNI (Java Native Interface).

Here is a good book on how to use JNI.

Basically you are just making a dll that will be loaded by Java which will call that native method. To get there though you will need to first sketch the class in Java that will use the function, let Javah generate the headers that you need (the functions need signatures that java can understand) and then use that to create the C/C++ code and then compile as a dll. I have done a couple of routines myself and it really is not hard although I had a couple of issues with linking myself.

here is another tutorial and if you google for "Using JNI" you will find lots of various examples.

However, you DO know that java has the ability to use the printer... no real need for a native interface for that.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1