简体   繁体   中英

Mapping of types: wchar_t*& and char*& in JNA

My client gave me dll with a couple of functions. Two of them are as follows:

int     getText(void* page, wchar_t*& pTextOut);
int     getTextJson(void* page, char*& jsonData);

I am using JNA and I am tring to write equivalent Java method in my interface:

int getText(Pointer pdfPage, ?? textOutput);
int getTextJson(Pointer pdfPage, ?? jsonData);

Unfortunately the following returns garbage

    Pointer outputTextPointer = outputText.getPointer();
    String outputStre = outputTextPointer.getString(0, "UTF-8");

The following returns and IndexOutOfBoundsException

    Pointer outputTextPointer = outputText.getPointer();
    String outputStre = outputTextPointer.getStringArray(0);

Can anyone recommend the correct java class to use to map the types wchar_t*& and char*& or how to get at the data correctly?

Thanks Damien

The following mappings work correctly for me

int getText(Pointer page, PointerByReference pTextOut);
int getTextJson(Pointer page, PointerByReference jsonData);

And then I use the following to get the data

PointerByReference pTextOut = new PointerByReference();
getText(page, pTextOut);
System.out.println(pTextOut.getValue().getWideString(0));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM