• Post Reply Bookmark Topic Watch Topic
  • New Topic

HRESULT and BSTR - Mapping in Java using JNI

 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am gona write a wrapper dll for a thirdparty dll being used in our project and i am stuck in the start.

One method signature of that dll is


Now, what signature should i have in java with "native" prefix so that i may be able to call that method with in my created dll.

What should i use for HRESULT and BSTR in java declarartion of this methoad.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't work that way.

You declare a method in Java, and use the javah tool to create a C/C++ header file. Then in C/C++ you implement the method described in the header by calling the C function. It's rather rare that you can directly call the method and return the result -- most of the time you'll need to use JNI library functions and your own C code to convert the arguments and result to the appropriate types. For example, a BSTR is a funky kind of Microsoft String object, and converting between them and C strings is complicated (and from there to Java Strings adds yet another step.) An HRESULT is just a 32-bit signed int, however, which presents no difficulties.

You'd probably want your native Java method to look like

public native int connectAsAdmin(String adminName, String password);

And then, as I said, your implementation would have to turn the Java Strings into BSTRs, which is nontrivial.
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:

And then, as I said, your implementation would have to turn the Java Strings into BSTRs, which is nontrivial.


Thanks. Can you point me to somewhere for the converstion BSTR to String, or some ground work that should i perfome before conversion in my C file.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google is your friend. Search for "BSTR Java String" for example.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!