Simplest way to create a VT_UI1 | VT_ARRAY VARIANT from a Java String?
21 views
Skip to first unread message
Markus Karg
unread,
Jan 25, 2024, 7:39:24 AMJan 25
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Java Native Access
The following code successfully creates a VARIANT from a Java String, where each Java char is one byte element n the SafeArray:
var byteArray = str.getBytes();
var safeArray = OaIdl.SAFEARRAY.createSafeArray(new WTypes.VARTYPE(VT_UI1), byteArray.length)) for (var i = 0; i < byteArray.length; i++) safeArray.putElement(byteArray[i], i); var variant = new VARIANT(safeArray);
I wonder if JNA has some utility that makes it much more convenient and spare some lines (and in particular the custom loop)? 🤔
Matthias Bläsing
unread,
Jan 25, 2024, 12:36:07 PMJan 25
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jna-...@googlegroups.com
var safeArray = OaIdl.SAFEARRAY.createSafeArray(new WTypes.VARTYPE(VT_UI1), byteArray.length);