For example CM_Get_Device_ID:
https://msdn.microsoft.com/en-us/library/windows/hardware/ff538405(v=vs.85).aspx
CMAPI
CONFIGRET
WINAPI CM_Get_Device_ID(
_In_ DEVINST dnDevInst,
_Out_ PWSTR Buffer,
_In_ ULONG BufferLen,
_In_ ULONG ulFlags
);
My current mapping is
int CM_Get_Device_IDA(int dnDevInst, byte[] Buffer, int BufferLen, int ulFlags);
which works.
However this leaves open the question of character encoding for the returned string (Buffer)
and what happens if it contains wide characters (don't know if in this particular instance this
is worry).
I can of course use the CM_Get_Device_IDW
int CM_Get_Device_IDW(int dnDevInst, byte[] Buffer, int BufferLen, int ulFlags);
or perhaps:
int CM_Get_Device_IDW(int dnDevInst, char[] Buffer, int BufferLen, int ulFlags);
but what is the preferred way, I read that JNA handles wide ASCII/UNICODE conversion
automatically (awesome) but I can't figure out all the details, this must be documented
somewhere but I can't find it. I found this:
https://github.com/java-native-access/jna/issues/377
but it doesn't really clarify this for me. Maybe it is just me.
Am I correct that if I specify W32APIOptions.UNICODE_OPTIONS when loading the library
I can always map PWSTR to char[] if the function is writing that parameter or
use String if the function is just taking the string in or returns it?
So how do I turn this (char[]) into a String in the preferred way?
JNA Native has toString(char[]) function but some Windows API functions take
an oversize buffer and return the length of the string but there is no
Native.toString(char[] chars,int offset, int len)
Of course there is
String(char[] chars,int offset, int len)
but as no encoding is mentioned I'm left in doubt. I suppose JNA maybe
clever enough to handle the encoding (if it is an issue) when it
passes and retrieves the char[] parameters?
cheers Kusti
This e-mail may contain confidential or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. We will not be liable for direct, indirect, special or consequential damages arising from alteration of the contents of this message by a third party or as a result of any virus being passed on or as of transmission of this e-mail in general.