Converting String to Pointer for JNA

后端 未结 3 1170
伪装坚强ぢ
伪装坚强ぢ 2020-12-21 01:19

I\'m trying to use JNA to query the effective permissions for a file in Windows. Eventually, I plan on using the GetEffectiveRightsFromAcl function, but to do so, I need to

3条回答
  •  失恋的感觉
    2020-12-21 02:04

    Assuming you want char * on the native side (you may need more memory allocated if the string contains non-ascii characters),

    String myString = "CURRENT_USER";
    Pointer m = new Memory(myString.length() + 1); // WARNING: assumes ascii-only string
    m.setString(0, myString); 
    

    You can then use m wherever you need to reference the "native" string.

    For wide strings (wchar_t *),

    String myString = "CURRENT_USER";
    Pointer m = new Memory(Native.WCHAR_SIZE * (myString.length() + 1));
    m.setWideString(0, myString);
    

提交回复
热议问题