CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    18

    How to implement BSTR in Java

    I am having a ComServer, and its outlined functions are implemneted in C++. Below is the Cpp function.

    HRESULT cIntuneServer::GetActiveProjectName(/*([out]*/ BSTR* nameOfProject)
    {
    CComBSTR projectName(L"\\Default\\");

    *nameOfProject = projectName;
    return S_OK;
    }



    I tried to implement the same function in Java:


    JIString outStr = new JIString("");
    dispatch.callMethod("GetActiveProjectName", new Object[]{outStr});
    System.out.println("Out String = "+outStr.toString();


    OUTPUT:

    Out String = [Type: 1 , []]

    How do i implement this in java?, I knew i am doing something worng, how do i get the BSTR* value to the OutStr in Java?

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: How to implement BSTR in Java

    I tried to implement the same function in Java:
    I don't understand what you mean. Are you trying to provide a Java implementation of the C++ code or are you trying to call the C++ code from your Java code.

    Unfortunately the Java code you have shown makes little sense unless you show/explain what a JIString is and what object type 'dispatch' is and what it's callMethod() method does.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Oct 2010
    Posts
    18

    Re: How to implement BSTR in Java

    Quote Originally Posted by keang View Post
    I don't understand what you mean. Are you trying to provide a Java implementation of the C++ code or are you trying to call the C++ code from your Java code.

    Hello Keang,
    I am just trying to do a java implementation of the C++ code, i want to write the same function in Java too. I am not calling any Cpp code

    Unfortunately the Java code you have shown makes little sense unless you show/explain what a JIString is and what object type 'dispatch' is and what it's callMethod() method does.
    Forget about the code, my aim is to implement the same function in Java too. In the JI is J-Interop "http://j-interop.org/".

    JISession session = null;
    IJIComObject sysInfoObject = null;
    IJIComObject sysInfoServer = null;
    IJIDispatch dispatch = null;
    String identifier = null;
    ControlSoft2(String[] args) throws JIException, UnknownHostException
    {
    session = JISession.createSession("localhost", "username", "password");
    session.useSessionSecurity(true);
    JIComServer comServer = new JIComServer(JIProgId.valueOf("application prog ID"), "localhost",session);
    sysInfoServer = comServer.createInstance();
    sysInfoObject = (IJIComObject)sysInfoServer.queryInterface("Com server inetrface");
    dispatch = (IJIDispatch)JIObjectFactory.narrowObject(sysInfoObject.queryInterface(IJIDispatch.IID));
    }


    private void PerformOp() throws JIException
    {
    JIString outStr = new JIString("");
    dispatch.callMethod("GetActiveProjectName", new Object[]{outStr});
    System.out.println("Out String = "+outStr.toString();
    }

    Now i have registered my interface into the dispatch object, i am just trying to call a method "GetActiveProjectName" from my com interface.

    My question is:

    Now i just have to call my function GetActiveProjectName(/*([out]*/ BSTR* nameOfProject) with a BSTR pointer which is an output parameter.

    How can i implement this in Java? Do i ahve to use CallBuilder? or use some other pointers etc.

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: How to implement BSTR in Java

    If JIString is based on java.lang.String then it is immutable and so you can't change its contents. You will either have to return the new value from the method or pass in an object that can be changed or pass in a object that has a callback method (normally done by implementing an interface defining the callback method).
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  5. #5
    Join Date
    Oct 2010
    Posts
    18

    Re: How to implement BSTR in Java

    private void PerformOp() throws JIException
    {
    JIString InputStr= new JIString("Project2");
    dispatch.callMethod("SetActiveProjectName", new Object[]{outStr});
    System.out.println("Out String = "+outStr.toString();
    }

    private void PerformOp() throws JIException
    {
    JIString InputStr= new JIString("Project2");
    dispatch.callMethod("DeleteProject", new Object[]{outStr});
    System.out.println("Out String = "+outStr.toString();
    }


    These two are working fine, new project is strating and projcts are getting deleted. Their Equivalent Cpp functions are

    HRESULT cIntuneServer::SetActiveProjectName(/*([in]*/ BSTR* nameOfProject)

    HRESULT cIntuneServer:eleteProject(/*([in]*/ BSTR* nameOfProject)

    So i think i need to do some extra work to make OutStr accept a value may be make it OuputParam type etc....

    Any ideas?

  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: How to implement BSTR in Java

    These two are working fine, new project is strating and projcts are getting deleted.
    These two methods both read from the value you are passing in and do not try to change it. See my previous post for why it can't be changed.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured