Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

New to Java, How to Implement BSTR in Java!!

821851Dec 7 2010 — edited Dec 7 2010
I am having a ComServer, and its outlined functions are implemneted in C++. Below is the Cpp function.

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

*nameOfProject = projectName;
return S_OK;
}
So this function is returning a pointer of BSTR whenever it is called. Below is an example when it is called:

CComBSTR activeProjectName = L"";
if(Server) {
// Retrieve active project name
Server->GetActiveProjectName(&activeProjectName);
}


I tried to implement the same function in Java:


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


OUTPUT:

Out String = [Type: 1 , []]

Here JI is J-Interop (http://j-interop.org/), all my code is in java i just have to write a function (or) perform a callmethod which has an output argument that accepts a BSTR* value. Please help me in this.

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

Edited by: user13430554 on Dec 7, 2010 7:00 AM

Edited by: user13430554 on Dec 7, 2010 7:02 AM


----------------------------------------------
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 xxxxxr::SetActiveProjectName(/*([in]*/ BSTR* nameOfProject)

HRESULT xxxxx::DeleteProject(/*([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?

Edited by: user13430554 on Dec 7, 2010 8:23 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 4 2011
Added on Dec 7 2010
1 comment
311 views