/** * @param target * If relative, resolved against the location of the symlink. * If absolute, it's absolute. * @throws UnsatisfiedLinkError * If the function is not exported by kernel32. * See http://msdn.microsoft.com/en-us/library/windows/desktop/aa363866(v=vs.85).aspx * for compatibility info. * @deprecated Use {@link Util#createSymlink} instead. */ @Deprecated public static void createSymbolicLink(File symlink, String target, boolean dirLink) throws IOException { if (!Kernel32.INSTANCE.CreateSymbolicLinkW( new WString(symlink.getPath()), new WString(target), dirLink?Kernel32.SYMBOLIC_LINK_FLAG_DIRECTORY:0)) { throw new WinIOException("Failed to create a symlink "+symlink+" to "+target); } }
/** * @deprecated Use {@link java.nio.file.Files#readAttributes} with * {@link java.nio.file.attribute.DosFileAttributes} and reflective calls to * WindowsFileAttributes if necessary. */ @Deprecated public static int getWin32FileAttributes(File file) throws IOException { // allow lookup of paths longer than MAX_PATH // http://msdn.microsoft.com/en-us/library/aa365247(v=VS.85).aspx String canonicalPath = file.getCanonicalPath(); String path; if(canonicalPath.length() < 260) { // path is short, use as-is path = canonicalPath; } else if(canonicalPath.startsWith("\\\\")) { // network share // \\server\share --> \\?\UNC\server\share path = "\\\\?\\UNC\\" + canonicalPath.substring(2); } else { // prefix, canonical path should be normalized and absolute so this should work. path = "\\\\?\\" + canonicalPath; } return Kernel32.INSTANCE.GetFileAttributesW(new WString(path)); }
@Override public Object toNative(Object value, ToNativeContext context) { if (value == null) return null; if (value instanceof String[]) { return new StringArray((String[])value, true); } return new WString(value.toString()); } @Override
/** Read back from native memory. */ @Override public void read() { boolean returnWide = original instanceof WString[]; boolean wide = NativeString.WIDE_STRING.equals(encoding); for (int si=0;si < original.length;si++) { Pointer p = getPointer(si * Native.POINTER_SIZE); Object s = null; if (p != null) { s = wide ? p.getWideString(0) : p.getString(0, encoding); if (returnWide) s = new WString((String)s); } original[si] = s; } }
if (SetCurrentProcessExplicitAppUserModelID(new WString(appID)).longValue() != 0) throw new RuntimeException("unable to set current process explicit AppUserModelID to: " + appID);
/** * Retrieves the short path form of the specified path. * * @param path the path * @return the short path name (or the original path if getting the short path name fails for any reason) */ static String getShortPathName(String path) { assert Constants.WINDOWS; try { final WString longPath = new WString("\\\\?\\" + path); // first we get the length of the buffer needed final int length = JNAKernel32Library.getInstance().GetShortPathNameW(longPath, null, 0); if (length == 0) { logger.warn("failed to get short path name: {}", Native.getLastError()); return path; } final char[] shortPath = new char[length]; // knowing the length of the buffer, now we get the short name if (JNAKernel32Library.getInstance().GetShortPathNameW(longPath, shortPath, length) > 0) { return Native.toString(shortPath); } else { logger.warn("failed to get short path name: {}", Native.getLastError()); return path; } } catch (final UnsatisfiedLinkError e) { return path; } }
} else if (type == WString.class) { Pointer p = getPointer(offset); result = p != null ? new WString(p.getWideString(0)) : null; } else if (Callback.class.isAssignableFrom(type)) {
value = new WString(((Pointer)value).getWideString(0));
public WStringPointer(String value) { super(); this.value = new WString(value); } @Override
public HRESULT Get(String wszName, int lFlags, VARIANT.ByReference pVal, IntByReference pType, IntByReference plFlavor) { return Get(wszName == null ? null : new WString(wszName), lFlags, pVal, pType, plFlavor); } }
/** Read back from native memory. */ public void read() { boolean returnWide = original instanceof WString[]; for (int si=0;si < original.length;si++) { String s = getPointer(si * Pointer.SIZE).getString(0, wide); original[si] = returnWide ? new WString(s) : (Object)s; } } }
private static class MemberOrder { public int first; public int middle; public int last; }
public static final HWND createWindowEx(final int exStyle, final String className, final String windowName, final int style, final int x, final int y, final int width, final int height, final HWND parent, final HMENU menu, final HINSTANCE instance, final LPVOID param) { final HWND hWnd = User32.INSTANCE .CreateWindowEx(exStyle, new WString(className), windowName, style, x, y, width, height, parent, menu, instance, param); if (hWnd == null) throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); return hWnd; }
public WebElement findElementByClassName(String using) { if (using == null) throw new IllegalArgumentException("Cannot find elements when the class name expression is null."); if (using.matches(".*\\s+.*")) { throw new IllegalLocatorException( "Compound class names are not supported. Consider searching for one class name and filtering the results."); } PointerByReference rawElement = new PointerByReference(); int result = lib.wdFindElementByClassName(driver, element, new WString(using), rawElement); handleErrorCode("id", using, result); return new InternetExplorerElement(lib, parent, rawElement.getValue()); }
public WebElement findElementById(String using) { PointerByReference rawElement = new PointerByReference(); int result = lib.wdFindElementById(driver, element, new WString(using), rawElement); handleErrorCode("id", using, result); return new InternetExplorerElement(lib, parent, rawElement.getValue()); }
public WebElement findElementByLinkText(String using) { PointerByReference rawElement = new PointerByReference(); int result = lib.wdFindElementByLinkText(driver, element, new WString(using), rawElement); handleErrorCode("link text", using, result); return new InternetExplorerElement(lib, parent, rawElement.getValue()); }
protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, String name, VARIANT[] pArgs) throws COMException { // variable declaration WString[] ptName = new WString[] { new WString(name) }; DISPIDByReference pdispID = new DISPIDByReference(); // Get DISPID for name passed... HRESULT hr = iDispatch.GetIDsOfNames(new REFIID(Guid.IID_NULL), ptName, 1, LOCALE_USER_DEFAULT, pdispID); COMUtils.checkRC(hr); return this .oleMethod(nType, pvResult, iDispatch, pdispID.getValue(), pArgs); }