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();
}
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);
}
}
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;
}
}
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);
}
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;
}
Aggregations