Hi Harkishan,
 
Thanks for the timely tips. However, now I am having a new prob.
As per the tips, I have a servlet class -- jniServlet -- in which I am declaring my native function as:
public native void cFunTest(int a);
In another class -- jniCall -- I am loading the library with 'static' keyword.
The native method -- cFunTest -- is in a C++ file -- c2.cpp.
Main C++ file is c1.cpp.
c1.cpp file is successfully compiled. When I try to compile c2.cpp, it throws the error -- " cannot execute '.\c2.dll' ".
c2 is the name I have given to the Dll.
Do c2.cpp needs to have a jniCall.h include file also? I have tried with it and the compiler is giving the above error.
May be i am doing something wrong.
Hoping to be corrected...soon!!!
 
Regards,
Rajneesh
 
-----------------------------------------------Source Code of all the files-------------------------------------------------------------------------------------------------------
 
jniServlet.java
 
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class jniServlet extends HttpServlet
{
 public native void cFunTest(int a);
 public void init(HttpServletRequest req, HttpServletResponse res) throws ServletException
 {     
 }
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
        PrintWriter out = res.getWriter();   
         out.println("This is a servlet call.");         
         out.close();         
        }    
public void destroy()
        {         
        }         
}
 
jniCall.java
public class jniCall

 static
 {
  System.loadLibrary("c2");
 }                                  
 public static void main(String args[])
 {                                   
  testDll test = new testDll();
  test.cFunTest(1234);
 }
}
 
c2.cpp
#include <jni.h>
#include "jniServlet.h"
#include "jniCall.h"
#include <stdio.h>
#include "c1.cpp"
JNIEXPORT void JNICALL
Java_testDll_cFunTest(JNIEnv *env, jobject obj,jint abc)
{
 informica* info = new informica();
    info->setdate(abc);
 info->getdate();
    return;
}
 
c1.cpp
# include <iostream.h>
# include <stdio.h>
class informica
 {
private: int i;
public:
   informica ()
   {
  cout<<"This is constructor";
   }
  void getdate()
  {
       cout<<"You entered --> "<<i<<"\n"<<"\a";
  }
  void setdate(int a)
  {
  i = a;
  }
};

Reply via email to