-
December 6th, 2010, 01:27 PM
#1
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?
-
December 6th, 2010, 05:30 PM
#2
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.
-
December 6th, 2010, 06:02 PM
#3
Re: How to implement BSTR in Java
Originally Posted by keang
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.
-
December 7th, 2010, 07:15 AM
#4
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).
-
December 7th, 2010, 11:21 AM
#5
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?
-
December 7th, 2010, 12:06 PM
#6
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|