I'm trying to use a generated interface by JNAerator from a typedef instruction, but I can't find a way to do that:
The function in the .h file is:
MyClass::Initialize(LPCWSTR path);
The header file also includes the original typedef instruction:
typedef __nullterminated CONST WCHAR *LPCWSTR, *PCWSTR;
JNAerator generates:
Method:
public native int Initialize(LPCWSTR path);
The interface:
/// Undefined type
/// Undefined type
public static interface LPCWSTR {
};
And the classes:
/// C type : WCHAR*
public Pointer<Short > LPCWSTR() {
try {
return (Pointer<Short >)BridJ.getNativeLibrary("dlls").getSymbolPointer("LPCWSTR").as(DefaultParameterizedType.paramType(Pointer.class, Short.class)).get();
}catch (Throwable $ex$) {
throw new RuntimeException($ex$);
}
}
/// C type : WCHAR*
public MainLibrary LPCWSTR(Pointer<Short > LPCWSTR) {
try {
{
BridJ.getNativeLibrary("dlls").getSymbolPointer("LPCWSTR").as(DefaultParameterizedType.paramType(Pointer.class, Short.class)).set(LPCWSTR);
return this;
}
}catch (Throwable $ex$) {
throw new RuntimeException($ex$);
}
}
The problem is, I don't know how to instantiate an object LPCWSTR
using Pointer
and the LPCWSTR
interface, using a String, so that I can pass it to the Initialize
method.
How can I do this?
UPDATE:
I modified the .h file to use wchar_t*
:
MyClass::Initialize(wchar_t* path)
JNAerator generated the method like this:
public native int Initialize(Pointer<Character > path);
So I called it like this:
MyClass factory = new MyClass();
Pointer<Character> path = org.bridj.Pointer.pointerToWideCString("dlls");
factory.Initialize(path);
The problem is that I get the following exception:
java.lang.UnsatisfiedLinkError: main.MyClass.Initialize(Lorg/bridj/Pointer;)I
at this line:
factory.Initialize(path);
What am I doing wrong?
I was having this problem too. zOlive’s response sent me down the right path. I changed the JNAerator library option to match my DLL name (e.g.
-library MyLib MyLib.dll MyLib.h
). That fixed it for me. There is more info about the library option here.