Search in sources :

Example 6 with WString

use of com.sun.jna.WString in project jna by java-native-access.

the class ProxyObject method resolveDispId.

protected DISPID resolveDispId(final IDispatch pDisp, String name) {
    assert COMUtils.comIsInitialized() : "COM not initialized";
    if (pDisp == null)
        throw new COMException("pDisp (IDispatch) parameter is null!");
    // variable declaration
    final WString[] ptName = new WString[] { new WString(name) };
    final DISPIDByReference pdispID = new DISPIDByReference();
    // Get DISPID for name passed...
    HRESULT hr = pDisp.GetIDsOfNames(new REFIID(Guid.IID_NULL), ptName, 1, factory.getLCID(), pdispID);
    COMUtils.checkRC(hr);
    return pdispID.getValue();
}
Also used : WString(com.sun.jna.WString) COMException(com.sun.jna.platform.win32.COM.COMException) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID)

Example 7 with WString

use of com.sun.jna.WString in project keystore-explorer by kaikramer.

the class KSE method main.

/**
 * Start the KeyStore Explorer application. Takes one optional argument -
 * the location of a KeyStore file to open upon startup.
 *
 * @param args
 *            the command line arguments
 */
public static void main(String[] args) {
    try {
        // To take affect these must be set before the splash screen is instantiated
        if (OperatingSystem.isMacOs()) {
            setAppleSystemProperties();
        } else if (OperatingSystem.isWindows7() || OperatingSystem.isWindows8() || OperatingSystem.isWindows10()) {
            String appId = props.getString("KSE.AppUserModelId");
            Shell32 shell32 = (Shell32) Native.loadLibrary("shell32", Shell32.class);
            shell32.SetCurrentProcessExplicitAppUserModelID(new WString(appId)).longValue();
        } else if (OperatingSystem.isLinux()) {
            fixAppClassName();
        }
        setInstallDirProperty();
        SplashScreen splash = SplashScreen.getSplashScreen();
        updateSplashMessage(splash, res.getString("KSE.LoadingApplicationSettings.splash.message"));
        ApplicationSettings applicationSettings = ApplicationSettings.getInstance();
        setCurrentDirectory(applicationSettings);
        updateSplashMessage(splash, res.getString("KSE.InitializingSecurity.splash.message"));
        initialiseSecurity();
        // list of files to open after start
        List<File> parameterFiles = new ArrayList<File>();
        for (String arg : args) {
            File parameterFile = new File(arg);
            if (parameterFile.exists()) {
                parameterFiles.add(parameterFile);
            }
        }
        // Create application GUI on the event handler thread
        updateSplashMessage(splash, res.getString("KSE.CreatingApplicationGui.splash.message"));
        SwingUtilities.invokeLater(new CreateApplicationGui(applicationSettings, splash, parameterFiles));
    } catch (Throwable t) {
        DError dError = new DError(new JFrame(), t);
        dError.setLocationRelativeTo(null);
        dError.setVisible(true);
        System.exit(1);
    }
}
Also used : WString(com.sun.jna.WString) JFrame(javax.swing.JFrame) ArrayList(java.util.ArrayList) SplashScreen(java.awt.SplashScreen) CreateApplicationGui(org.kse.gui.CreateApplicationGui) WString(com.sun.jna.WString) File(java.io.File) DError(org.kse.gui.error.DError)

Example 8 with WString

use of com.sun.jna.WString in project crate by crate.

the class JNANatives method getShortPathName.

/**
 * 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;
    }
}
Also used : WString(com.sun.jna.WString)

Example 9 with WString

use of com.sun.jna.WString in project jna by java-native-access.

the class COMBindingBaseObject method oleMethod.

protected HRESULT oleMethod(int nType, VARIANT.ByReference pvResult, IDispatch pDisp, String name, VARIANT[] pArgs) throws COMException {
    if (pDisp == null)
        throw new COMException("pDisp (IDispatch) parameter is null!");
    // variable declaration
    WString[] ptName = new WString[] { new WString(name) };
    DISPIDByReference pdispID = new DISPIDByReference();
    // Get DISPID for name passed...
    HRESULT hr = pDisp.GetIDsOfNames(new REFIID(Guid.IID_NULL), ptName, 1, LOCALE_USER_DEFAULT, pdispID);
    COMUtils.checkRC(hr);
    return this.oleMethod(nType, pvResult, pDisp, pdispID.getValue(), pArgs);
}
Also used : WString(com.sun.jna.WString) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) DISPIDByReference(com.sun.jna.platform.win32.OaIdl.DISPIDByReference) REFIID(com.sun.jna.platform.win32.Guid.REFIID)

Example 10 with WString

use of com.sun.jna.WString in project intellij-community by JetBrains.

the class NativeFileManager method getProcessesUsing.

public static List<Process> getProcessesUsing(File file) {
    List<Process> processes = new LinkedList<>();
    // If the DLL was not present (XP or other OS), do not try to find it again.
    if (ourFailed) {
        return processes;
    }
    try {
        IntByReference session = new IntByReference();
        char[] sessionKey = new char[Win32RestartManager.CCH_RM_SESSION_KEY + 1];
        int error = Win32RestartManager.INSTANCE.RmStartSession(session, 0, sessionKey);
        if (error != 0) {
            Runner.logger().warn("Unable to start restart manager session");
            return processes;
        }
        StringArray resources = new StringArray(new WString[] { new WString(file.toString()) });
        error = Win32RestartManager.INSTANCE.RmRegisterResources(session.getValue(), 1, resources, 0, Pointer.NULL, 0, null);
        if (error != 0) {
            Runner.logger().warn("Unable to register restart manager resource " + file.getAbsolutePath());
            return processes;
        }
        IntByReference procInfoNeeded = new IntByReference();
        Win32RestartManager.RmProcessInfo info = new Win32RestartManager.RmProcessInfo();
        Win32RestartManager.RmProcessInfo[] infos = (Win32RestartManager.RmProcessInfo[]) info.toArray(MAX_PROCESSES);
        IntByReference procInfo = new IntByReference(infos.length);
        error = Win32RestartManager.INSTANCE.RmGetList(session.getValue(), procInfoNeeded, procInfo, info, new LongByReference());
        if (error != 0) {
            Runner.logger().warn("Unable to get the list of processes using " + file.getAbsolutePath());
            return processes;
        }
        for (int i = 0; i < procInfo.getValue(); i++) {
            processes.add(new Process(infos[i].Process.dwProcessId, new String(infos[i].strAppName).trim()));
        }
        Win32RestartManager.INSTANCE.RmEndSession(session.getValue());
    } catch (Throwable t) {
        // Best effort approach, if no DLL is found ignore.
        ourFailed = true;
    }
    return processes;
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) WString(com.sun.jna.WString) LinkedList(java.util.LinkedList) WString(com.sun.jna.WString) StringArray(com.sun.jna.StringArray) LongByReference(com.sun.jna.ptr.LongByReference)

Aggregations

WString (com.sun.jna.WString)12 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)7 REFIID (com.sun.jna.platform.win32.Guid.REFIID)4 PointerByReference (com.sun.jna.ptr.PointerByReference)4 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)3 CLSID (com.sun.jna.platform.win32.Guid.CLSID)2 LCID (com.sun.jna.platform.win32.WinDef.LCID)2 StringArray (com.sun.jna.StringArray)1 COMException (com.sun.jna.platform.win32.COM.COMException)1 USHORTByReference (com.sun.jna.platform.win32.WinDef.USHORTByReference)1 IntByReference (com.sun.jna.ptr.IntByReference)1 LongByReference (com.sun.jna.ptr.LongByReference)1 SplashScreen (java.awt.SplashScreen)1 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 JFrame (javax.swing.JFrame)1 Shell32Ex (org.jumpmind.symmetric.wrapper.jna.Shell32Ex)1 Before (org.junit.Before)1