Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can anybody help  RSS feed

 
dhriti joshi
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
i want to call a c++ dll from java,but i can not make any change in the c++ code as i have only the compiled version with me.so i think i can not use jni.is there any other way?
dhriti
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SCJP exam does not include JNI.
Moving this to Other Java APIs forum.
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I believe there are a few options available to you. Now, the way JNI works you'll need something on the native side that sends/receives Java Objects/Primitives (there are C/C++ types for this):
"While "in the real world" you probably have existing C functions that you wish to integrate with Java programs, you will still need to modify the signatures for these C functions to work with the JNI."
However, don't worry this gives you two options:
1. Write a wrapper in C/C++ that brokers all requests to the C++ DLL you wish to use.
So if you had a method in C++ (Iam NOT a C++ person):
public char[] getName();
you could make a wrapper C/C++ method:
JNIEXPORT jstring JNICALL Java_Prompt_getName(JNIEnv *, jobject);
That would just call the C++ method and then alter it slightly for sending to java.
(If you can't write C/C++, there's another option)
2. Use a COM broker or Java/Win32 integration product. There are plenty of free ones:
  • Jacob (Free):

  • http://danadler.com/jacob/
  • Jawin (Free):

  • http://staff.develop.com/halloway/code/jawin.html

    These allow you to work with C/C++ DLLs from Java.
    Good Luck!
    [ August 13, 2002: Message edited by: Robert Paris ]
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!