On Jan 31, 2008, at 3:40 PM, tho...@atunes.org wrote:
Hi,
I want to call GetShortPathNameW (http://msdn2.microsoft.com/en-us/
library/aa364989(VS.85).aspx). What is the right mapping for
LPCTSTR and LPTSTR? Maybe this?:
public interface Kernel32 extends StdCallLibrary {
public int GetShortPathNameW(PointerByReference lpszLongPath,
PointerByReference lpszShortPath, int cchBuffer);
}
Use char[] to represent an array of wchar_t (which is what LPCTSTR is
for W-suffixed w32 API methods). If you use the w32 unicode api
mappings (see W32API.DEFAULT_OPTIONS), you can pass String for read-
only native strings. You can then use Native.toString to convert the
populated buffer back to a String.
This is one of my attemps but it doesn't work
(java.lang.IndexOutOfBoundsException: Bounds exceeds available
space : size=4, offset=112)
public class NativeCallUtils {
private static Kernel32 INSTANCE;
static {
System.setProperty("jna.encoding", "UTF8");
INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
}
Setting the encoding is only necessary for the A-suffixed w32 API
methods.
public static String getEightPointThreePathName(String longPathName) {
PointerByReference pbr = new PointerByReference();
pbr.getPointer().setString(0, "\\\\?\\" + longPathName);
PointerByReference pbr2 = new PointerByReference();
INSTANCE.GetShortPathNameW(pbr, pbr2, longPathName.length());
String s = pbr2.getValue().getString(0);
return s;
}
}
Sorry, if this is actually a dumb question but I haven't done much
C/C++ programming so far.