dcsimg
Calling a C++ function from a Java class
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Viraj_Patil
Posted On:   Wednesday, September 3, 2003 01:19 PM

I am trying to call a C++ function from a java class. The java class compiles and I also get the header file when I run javah on the class but when I try running the app, its throwing exceptions. Here is my java code below, the c++ class is a working piece of code. Please let me know what I might be doing wrong here. The C++ function I am trying to call is : VerifyID(BSTR CalcID, BSTR PublicKey, short *rc) Java class: public class certify { static { try { System.loadLibrary("Certificate"); } catch( UnsatisfiedLinkError x ) { System.out.println("Err   More>>

I am trying to call a C++ function from a java class.
The java class compiles and I also get the header file when I run javah on the class but when I try running the app, its throwing exceptions.
Here is my java code below, the c++ class is a working piece of code.
Please let me know what I might be doing wrong here.




The C++ function I am trying to call is :

VerifyID(BSTR CalcID, BSTR PublicKey, short *rc)

Java class:



public class certify {



static {

try {

System.loadLibrary("Certificate");

}

catch( UnsatisfiedLinkError x )

{

System.out.println("Error in static code");

}



}



certify() {

try {

cplusPtr = initCplusSide();

}

catch( UnsatisfiedLinkError x )

{

System.out.println("Error in certify constructor");

}



}


public native short VerifyId(int cplusPtr, String calcId, String publicKey);




private native int initCplusSide();



private int cplusPtr;


public static void main (String [] args) {



String calcId = "123";

String publicKey = "123456";



short retCode = 0;



try {



certify cert = new certify();



retCode = cert.VerifyId(cert.cplusPtr, calcId, publicKey);



System.out.println("retCode is: "+retCode);

}

catch( UnsatisfiedLinkError x )

{

System.out.println("Error in certify main");

}


}

}


   <<Less

Re: Calling a C++ function from a Java class

Posted By:   Viraj_Patil  
Posted On:   Wednesday, September 3, 2003 02:01 PM

this is the stack trace:



java.lang.UnsatisfiedLinkError: no Certificate in java.library.path

at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1344)

at java.lang.Runtime.loadLibrary0(Runtime.java:744)
at java.lang.System.loadLibrary(System.java:815)

at certify.(certify.java:5)

About | Sitemap | Contact