[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-java-com
Subject:    Re: String/StringBuffer return type with J/Direct?
From:       Philipp Breuss <Philipp () UMBRIEL ! AMSINC ! COM>
Date:       1998-12-22 22:04:07
[Download RAW message or body]


Tracy, I think this was the answer I needed!
Thanks a lot -
Philipp

-----Original Message-----
From: Tracy Sharpe [mailto:tracysh@MICROSOFT.COM]
Sent: Tuesday, December 22, 1998 3:47 PM
To: Java-COM@DISCUSS.MICROSOFT.COM
Subject: Re: String/StringBuffer return type with J/Direct?


Philipp,

As you've found, the MS VM doesn't support marshaling a plain char* type to
a Java type.

If you have control over the API, you can either add methods that explicitly

take a StringBuffer as an input parameter or follow the OLE design pattern
of
having an [out,retval] parameter as the last parameter to the method.

Or you can use DllLib to do the marshaling yourself:

/** @dll.import("myDll", entrypoint="ProfGetUserID") */
private static native int ProfGetUserID_I();

public String ProfGetUserId() {
        // Get the pointer to the raw (owned by who?) memory.
        int ptr = ProfGetUserID_I();
        // Create a string out of the ANSI buffer.
        return com.ms.dll.DllLib.ptrToStringAnsi(ptr);
}

Tracy

-----Original Message-----
From: Philipp Breuss [mailto:Philipp@UMBRIEL.AMSINC.COM]
Sent: Tuesday, December 22, 1998 12:26 PM
To: Java-COM@DISCUSS.MICROSOFT.COM
Subject: String/StringBuffer return type with J/Direct?


I am accessing a C DLL using J/Direct and have problems passing a char* back
as a return parameter?
The C function definition of the DLL looks like this:
char* ProfGetUserId();
and it returns a pointer to a character string. According to the SDK
tutorial I can use StringBuffer as the Java type which maps to the char*.
However, when I run my program, I get a
java.lang.UnsatisfiedLinkError: test.ProfGetUserId Method signature contains
an untranslatable type.
Any experiences?

Here is my Java example:

public class test {
   public static void main(String args[])
   {
        StringBuffer uid = new StringBuffer(8);

        // Here I am calling my native function and here I am getting
        // my UnsatisfiedLinkError
        uid = ProfGetUserId();
   }

   /** @dll.import("myDll") */
   public static native StringBuffer ProfGetUserId ();
}

----------------------------------------------------------------
Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://discuss.microsoft.com/archives/index.html

----------------------------------------------------------------
Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://discuss.microsoft.com/archives/index.html

----------------------------------------------------------------
Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://discuss.microsoft.com/archives/index.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic