Calling c++ function in java

Hi,
I would like to know how I can modify c++ program so that I can use its(c++) functions in java.
the program is c++ ready-made and i would like to use its functions in a java package.
i read the turiols concerning this on java.sun.com but does that mean that i have append "jni.h", "JNIEXPORT", etc to the c++ file?
Hints shall be appreciated.
Thanks.

OK, thanks.I have tried the jni procedure but without success.
Is it possible for Java talk to native code (c++) via TCP/IP.
Please advice of any links/knowledge.
Thanks.
1. Strictly speaking, java does not operate on C++; it
operates on C functions. This is more than a quibble:
o JNI expects to call C functions, not methods of C++
objects.
o In fact, if you really just have functions, but they
are compiled as C++, then you will probably have to
declare C linkage.
2. Functions called from java must conform to JNI
calling conventions.
o In general, the starting point is to define how you
would like the object and native method to look in
java, then run jni.h to generate the appropriate C
header definitions, then write the C code.
o Functions called from java must exist in shared
libraries - on Windows, in dlls.
o Existing C function libraries are typically accessed
by writing a "wrapper" dll that implements the
required java interface and then calls the existing
library functions.
o In fact, a wrapper could actually instantiate C++
objects and call their methods.
3. You might care to look up something called JACE,
which some people claim can generate the kinds of
wrappers discussed here.

Similar Messages

  • Calling c functions in java

    How do I call c functions from java?

    See http://java.sun.com/docs/books/tutorial/native1.1/index.html

  • ADF: Can i call javascript function from java clsss method in ADF?

    Hi,
    I want to call javascript function in Java class method, is it possible in ADF? , if yes then how?
    or I need to use Java 6 feature directely?
    Regards,
    Deepak

    private void writeJavaScriptToClient(String script)
    FacesContext fctx = FacesContext.getCurrentInstance();
    ExtendedRenderKitService erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
    erks.addScript(fctx, script);
    }usage
    StringBuilder script = new StringBuilder();
    script.append( "var popup = AdfPage.PAGE.findComponentByAbsoluteId('p1');");
    script.append("if(popup != null){"); script.append("popup.show();"); script.append("}");
    writeJavaScriptToClient(script.toString());Timo

  • Calling C++ functions by Java via CORBA?

    Hello,
    I am interested in source code examples of calling C++ functions by Java via CORBA. For example the client is in Java and the server is in C++. Is it posible that the IDL compiler can generate "java" client stubs and "c++" server sceleton? So the implementation of the client will "inherit" the stubs generated by the IDL compiler, and the server implementation will use the sceleton.
    Thank you in advance.

    As far as I know, you've got to have your idl on both side. You compile idl mapping to java on client side and mapping to C++ on server side. Then you should be able to do it.
    Kim

  • Call DLL function from JAVA

    HI!
    What's the best way (and simple) to call DLL function from JAVA.
    DLL function (developed in C) has two input parameters (string) and return an integer.
    Could you help with an example?
    Thanks a lot.

    Do a google search for 'JNI tutorial' and it will turn up hundreds of examples.

  • Calling c function from java!!

    hi all,
    I want to call c function from java . I have gone through the link http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html for JNI.
    According to this link we need to write the native method implementation in such a way that the method signature should exactly match the method signature created in the header file.
    My problem is that i have a c application which i cannot modify in any ways i.e., i cannot change its code. But i want to call its function from my java code.
    Please suggest me appropriate solution for this. Please let me know whether it can be done using JNI or is there any other method for this.
    thanks

    This link is amazing since those sources were wrote in 1998 and I started to develop JNative in 2004. I did not found them when I started.
    Since JNative can deal with callbacks and probably COM in a near future, I expect to see it living to Dolphin at least.
    --Marc (http://jnative.sf.net)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to call a function from Java to JSP

    Hello,
    I have a question about using tags.
    I have a java file,which has a function. Now I want to call this function into my JSP page.
    I'm using JSP 1.2 and TOMCAT 4.1 with Java2 SDK.
    I search through the web and find a method to do this.Bu it requires JSP 2.0
    But I try that in my machine(using JSP 1.2).It gives an error:
    Did you know what is the error? Or is there any method to call a function into my JSP page?
    Please, help me to solve this.
    Here are my codes(part of them)
    UserPassword.java file
    package data;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import javax.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class UserPassword
         public static String verify(String username,String password){
              // some codes
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE taglib
            PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
         "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
      <tlib-version>1.0</tlib-version>
      <jsp-version>1.2</jsp-version>
      <short-name>simple</short-name>
      <uri>http://jakarta.apache.org/tomcat/HRM/WEB-INF/lib</uri>
      <description>
         A  tab library for the login
      </description>
    <function>
            <description>verify username and password</description>
            <name>verify</name>
            <function-class>data.UserPassword</function-class>
            <function-signature>String verify(java.lang.String,java.lang.String)
            </function-signature>
    </function>
    </taglib>I put this file into the webapps/HRM/WEB-INF/lib folder
    Here is my JSP file.
    <%@ page language="java" %>
    <%@ page import="data.UserPassword" %>
    <%@ page session="true" %>
    <%@ taglib prefix="login" uri="/WEB-INF/lib/LoginVerify.tld" %>
    <jsp:useBean id="useraccount" class="data.UserPassword"/>
    <jsp:setProperty name="useraccount" property="*"/>
    <%
    String status = UserPassword.verify(String username,String password);
    String nextPage = "MainForm.jsp";
    if(status.equals("InvalidU")) nextPage ="InvalidUserName.jsp";
    if(status.equals("InvalidP")) nextPage ="InvalidPassword.jsp";
    if(status.equals("main")) nextPage ="MainForm.jsp";
    %>
    <jsp:forward page="<%=nextPage%>"/>
    Here is the error:
    org.apache.jasper.JasperException: XML parsing error on file /WEB-INF/lib/LoginVerify.tld: (line 18, col -1): Element "taglib" does not allow "function" here.
         at org.apache.jasper.xmlparser.ParserUtils.parseXMLDocument(ParserUtils.java:189)
         at org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:247)
         at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:183)
         at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:354)
         at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:381)Please, help me to solve this trouble.
    Thanks.

    Yes. As serlank showed, you can just call the function easily in scriptlet tags
    However the whole point of a tag library is to avoid the use of scriptlets.
    Seeing as you can't use functions, is just to do it as a standard tag.
    ie in your jsp
    <login:verify name="<%= userName %>" password = "<%= password %>" resultVar = "status"/>
    <c:choose>
      <c:when test="${status == 'InvalidU'}">
        <c:set var="nextPage" value="InvalidUserName.jsp"/>
      </c:when>
      <c:when test="${status == 'InvalidP'}">
        <c:set var="nextPage" value="InvalidPassword.jsp"/>
      </c:when>
    </c:choose>In your case, this tag in the tld would possibly look something like this.
    You would then have to write a tag handler class that would call the function you want.
    <tag>
      <name>verify</name>
      <tagclass>com.tags.login.Verify</tagclass>
      <teiclass>com.tags.login.VerifyTEI</teiclass>  (if required)
      <bodycontent>JSP</bodycontent>
    // name attribute 
    <attribute>
          <name>name</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
        </attribute>
    // password attribute
        <attribute>
          <name>password</name>
          <required>true</required>
          <rtexprvalue>true</rtexprvalue>
        </attribute>
    // result variable to return a response from the tag.
      <variable>
        <name-from-attribute >resultVar</name-from-attribute >
        <variable-class>java.lang.String</variable-class>
        <declare>true</declare>
        <scope>AT_END</scope>
      </variable>
    </tag>Hope this helps some, and doesn't confuse too much :-)
    Cheers,
    evnafets

  • How do I call a function in java?

    I'm calling a function called lightParse() from the method. But, I'm getting an error:
    F:\Data>javac -classpath xerces.jar;xalan.jar;classpath%; Test.java
    Test.java:22: lightParse(java.lang.String) in Test cannot be applied to ()
    lightParse();
    ^
    The scenario or code portion is :
    import javax.swing.*;
    import java.awt.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class Test extends JFrame
         JList list;
         JScrollPane listContainer;
         public Test()
              setSize(300, 300);
              setVisible(true);
              initialize();
              lightParse(); // calling the function
         public void initialize()
              list = new JList(new DefaultListModel()); // Set the initial model
              listContainer = new JScrollPane(list);
              listContainer.setSize(new Dimension(200, 200));
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(listContainer, "Center");
              validate(); // Validate the screen
    // The function is the following
         public void lightParse(String url)
              DocumentBuilder parser;
              DocumentBuilderFactory factory =
                        DocumentBuilderFactory.newInstance();
              try {
                        parser = factory.newDocumentBuilder();
                        Document doc = parser.parse(url);
    How do I call the function correctly with the right parameter?
    Thanks in advance for the answer.

    u r calling lightParse method without passing the expected "String" argument. There must not be an overloaded method for lightParse without any arguments.
    So u should use this:
    lightParse(some string here);
    Hope this explains.
    I'm calling a function called lightParse() from the
    method. But, I'm getting an error:
    F:\Data>javac -classpath
    xerces.jar;xalan.jar;classpath%; Test.java
    Test.java:22: lightParse(java.lang.String) in Test
    cannot be applied to ()
    lightParse();
    ^
    The scenario or code portion is :
    import javax.swing.*;
    import java.awt.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class Test extends JFrame
    JList list;
    JScrollPane listContainer;
    public Test()
    setSize(300, 300);
    setVisible(true);
    initialize();
    lightParse(); // calling the function
    public void initialize()
    list = new JList(new DefaultListModel()); // Set the
    e initial model
    listContainer = new JScrollPane(list);
    listContainer.setSize(new Dimension(200, 200));
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(listContainer, "Center");
    validate(); // Validate the screen
    // The function is the following
    public void lightParse(String url)
    DocumentBuilder parser;
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    try {
    parser = factory.newDocumentBuilder();
    Document doc = parser.parse(url);
    How do I call the function correctly with the right
    parameter?
    Thanks in advance for the answer.

  • ORA-00911: invalid character - Calling a function from Java..

    Hi to all.. I have an issue when calling an oracle function from Java..
    This is my Java code:
    final StringBuffer strSql = new StringBuffer();
    strSql.append("SELECT GET_TBL('II_2_1_6_5') AS TABLA FROM DUAL;");
    st = conexion.createStatement();
    rs = st.executeQuery(strSql.toString());
    and in the executeQuery a SQLException is throwed:
    java.sql.SQLException: ORA-00911: invalid character
    I paste the query in TOAD and it works.. :S
    anybody knows how can I solve this?

    Remove the Semicolon after Dual.
    strSql.append("SELECT GET_TBL('II_2_1_6_5') AS TABLA FROM DUAL");
    Sushant

  • Calling OCI functions from Java

    Is it possible to call OCI's API functions from Java and create a Lightweight Session ?
    Please help me out.

    I too would like to know how this can be accomplished. I have
    seen several posts that claim it is possible with Oracle91.

  • Can we call sql function  in java

    as i know i can call stored procedures ,but can i call pl/sql functions.

    Using JDBC you can execute any valid sql statement.
    For a pl/sql function you use a CallableStatement and the syntax:
    {?= call <procedure-name>[<arg1>,<arg2>, ...]}
    http://java.sun.com/j2se/1.5.0/docs/api/java/sql/CallableStatement.html

  • Calling oracle Function from java

    first of all ... i don't know english very vell and sorry about it ..... then ...
    i've created table in oracle :
    create table STUDENT
    ID NUMBER,
    NAME VARCHAR2(50),
    SURNAME VARCHAR2(50),
    AGE NUMBER
    and than i've wrote function like that :
    create or replace function sf_SearchStudent
    nID in number
    return MyPackage.CursorType is
    Result MyPackage.CursorType;
    begin
    open Result for select * from STUDENT where ID=nID;
    return Result;
    end sf_SearchStudent;
    and it's working fine but in java i wrote code like that :
    CallableStatement callst = conn.prepareCall("{?=call sf_SearchStudent(?,?,?,?)}");
    callst.registerOutParameter(1, OracleTypes.CURSOR);
    callst.setInt(1,id);
    callst.setString(2,name);
    callst.setString(3,surname);
    callst.setInt(4,age);
    callst.executeUpdate(); ------->>>>> ERROR Occur
    ResultSet res = ((OracleCallableStatement)callst).getCursor(1);
    while (res.next())
    System.out.println(res.getInt("ID"));
    System.out.println(res.getString("NAME"));
    System.out.println(res.getString("SURNAME"));
    System.out.println(res.getInt("AGE"));
    but here is an error and i don't know why :( ....... please help me ..... F!
    error type :
    java.sql.SQLException: Missing IN or OUT parameter at index:: 5

    no it's not a problem ........ I so already tried, but a mistake all the same was. After that I a little bit simplified.
    ok consequently i did oracle procedure like that :
    create or replace function sf_SearchStudent
    nID in number
    return MyPackage.CursorType is
    wCursor MyPackage.CursorType;
    begin
    open wCursor for Wselect;
    return wCursor;
    end sf_SearchStudent;
    and the java source code looks like that :
    CallableStatement callst = conn.prepareCall("{?=call sf_SearchStudent(?,?,?,?)}");
    callst.registerOutParameter(1, OracleTypes.CURSOR);
    callst.setString(1, name);
    callst.executeUpdate(); ------------------>>>>>>>>>> HERE IS AN ERROR ------------<<<<<<<<<<<<
    ResultSet res = ( (OracleCallableStatement) callst).getCursor(4);
    while (res.next())
    System.out.println(res.getInt("ID"));
    System.out.println(res.getString("NAME"));
    System.out.println(res.getString("SURNAME"));
    System.out.println(res.getInt("AGE"));
    error type :
    java.sql.SQLException: Missing IN or OUT parameter at index:: 3

  • Call C function from Java

    Hi
    How do I call a C function from a java applet. Any ideas.
    Thanks
    Jay

    How do I call a C function from a java applet.
    You're going to run into problems here even after you figure out all the JNI details. Loading a shared object from an applet violates the security model - you will have to sign the applet. In addition, to be cross-platform (I'm using linux now), you will have to provide multiple dll/so - one for each architecture...

  • Call peoplesoft function from java code

    Can we call the peoplesoft decrypt function from within java code ?

    Hi Sumit,
    For getting the connection, I would use something like:
    import com.sap.mw.jco.JCO;
    public class R3Connector {
         private JCO.Client jcoclient = null;
         public  R3Connector () {
                   super();
         public JCO.Client getClient() {
              if (jcoclient == null) {
                   /* get connection from Pool */
                   jcoclient = JCO.getClient (POOL_NAME);
              return jcoclient;
         public void releaseClient() {
              if (jcoclient != null) {
                   JCO.releaseClient(jcoclient);     
    and of course you will have to define your POOL property somewhere (portalapp.xml presumably)
    Hope this helps!

  • Calling c functions from java

    i need to call from my java program to c functions that get
    c structs as a parameters in their prototype.
    as you probablly know java is not working with structs (classes only), so my question is how can i do it , i mean call the c functions that gets structs as parameters form java????

    1. Define java objects that hold the same data as the structs.
    2. Write C code that can take the java objects as parameters, call their methods to retrieve the data, and create C structs.
    3. Call the C routines that use the structs.

Maybe you are looking for

  • BBP_GET_STATUS_2 only works when entering SC number

    Hi all. SRM 4.0. I am seeing some strange behaviours in my system these days. The job BBP_GET_STATUS_2 is set up in batch to run every 5 minutes, but now I am seeing issues where the documents are not properly updated in SRM. The case is that in the

  • Creating a PDF from printer

    Can anyone tell my how I can print/create a pdf from my printer - I used to be able to & now I can't it doesn't give me the option anymore

  • Implicit Fact Column - am I thinking about this the right way?

    My exploration of the Implicit Fact Column is below. Let me know if you think this is the intended usage. When the BI Server sees a request where one Dimension is being constrained by another, it has to pick a fact table that contains references to t

  • How do i uninstall safari6.

    I have tried to uninstall the safari 6 by removing safari app contents manually but 10.8.2 doesnt allow to uninstall the safari and everything went clumsy. Now iam unable to open safari even after reinstalling. Now how can get my old safari atleast.

  • 8i, 9i, 10g 가 한드라이브에 모두 깔리죠?

    안녕하세요. 제 피씨에 c드라이브에 9i client, 10g데이터베이스가 깔렸는데요 여기다가 8i클라이언트를 깔라고 하는데 안깔리는데.. 세버전 모두 한곳에 깔리죠?? 이상하네... 왜 안깔릴까요?? 아예...커서도 안먹고, autorun해서야 겨우 화면뜨는데 install클릭하면 다시 마법사가 죽어버리네요..쩝. 이런 황당한 경우가...!!!