use of com.sun.jna.Pointer in project jna by java-native-access.
the class W32Service method getFailureActions.
/**
* Get the failure actions of the specified service. Corresponds to
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms681988.aspx">QueryServiceConfig2</a>
* with parameter dwInfoLevel set to SERVICE_CONFIG_FAILURE_ACTIONS.
*/
public SERVICE_FAILURE_ACTIONS getFailureActions() {
Pointer buffer = queryServiceConfig2(Winsvc.SERVICE_CONFIG_FAILURE_ACTIONS);
SERVICE_FAILURE_ACTIONS result = new SERVICE_FAILURE_ACTIONS(buffer);
return result;
}
use of com.sun.jna.Pointer in project jna by java-native-access.
the class OpenGL32Util method countGpusNV.
/**
* Count GPUs
* @return the number of available GPUs
*/
public static int countGpusNV() {
// create a dummy window
HWND hWnd = User32Util.createWindow("Message", null, 0, 0, 0, 0, 0, null, null, null, null);
HDC hdc = User32.INSTANCE.GetDC(hWnd);
// set a compatible pixel format
PIXELFORMATDESCRIPTOR.ByReference pfd = new PIXELFORMATDESCRIPTOR.ByReference();
pfd.nVersion = 1;
pfd.dwFlags = WinGDI.PFD_DRAW_TO_WINDOW | WinGDI.PFD_SUPPORT_OPENGL | WinGDI.PFD_DOUBLEBUFFER;
pfd.iPixelType = WinGDI.PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = WinGDI.PFD_MAIN_PLANE;
GDI32.INSTANCE.SetPixelFormat(hdc, GDI32.INSTANCE.ChoosePixelFormat(hdc, pfd), pfd);
// create the OpenGL context to get function address
WinDef.HGLRC hGLRC = OpenGL32.INSTANCE.wglCreateContext(hdc);
OpenGL32.INSTANCE.wglMakeCurrent(hdc, hGLRC);
Pointer funcPointer = OpenGL32.INSTANCE.wglGetProcAddress("wglEnumGpusNV");
Function fncEnumGpusNV = (funcPointer == null) ? null : Function.getFunction(funcPointer);
OpenGL32.INSTANCE.wglDeleteContext(hGLRC);
// destroy the window
User32.INSTANCE.ReleaseDC(hWnd, hdc);
User32Util.destroyWindow(hWnd);
// abort if the nVidia extensions are not present
if (fncEnumGpusNV == null)
return 0;
// enumerate nVidia adapters
HGLRCByReference hGPU = new HGLRCByReference();
for (int i = 0; i < 16; i++) {
Boolean ok = (Boolean) fncEnumGpusNV.invoke(Boolean.class, new Object[] { Integer.valueOf(i), hGPU });
if (!ok.booleanValue())
return i;
}
return 0;
}
use of com.sun.jna.Pointer in project intellij-community by JetBrains.
the class Restarter method restartOnWindows.
private static void restartOnWindows(String... beforeRestart) throws IOException {
Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
Shell32 shell32 = (Shell32) Native.loadLibrary("shell32", Shell32.class);
int pid = kernel32.GetCurrentProcessId();
IntByReference argc = new IntByReference();
Pointer argvPtr = shell32.CommandLineToArgvW(kernel32.GetCommandLineW(), argc);
String[] argv = getRestartArgv(argvPtr.getWideStringArray(0, argc.getValue()));
kernel32.LocalFree(argvPtr);
// See https://blogs.msdn.microsoft.com/oldnewthing/20060515-07/?p=31203
// argv[0] as the program name is only a convention, i.e. there is no guarantee
// the name is the full path to the executable.
//
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197(v=vs.85).aspx
// To retrieve the full path to the executable, use "GetModuleFileName(NULL, ...)".
//
// Note: We use 32,767 as buffer size to avoid limiting ourselves to MAX_PATH (260).
char[] buffer = new char[32767];
if (kernel32.GetModuleFileNameW(null, buffer, new WinDef.DWORD(buffer.length)).intValue() > 0) {
argv[0] = Native.toString(buffer);
}
List<String> args = new ArrayList<>();
args.add(String.valueOf(pid));
args.add(String.valueOf(beforeRestart.length));
Collections.addAll(args, beforeRestart);
args.add(String.valueOf(argv.length));
Collections.addAll(args, argv);
runRestarter(new File(PathManager.getBinPath(), "restarter.exe"), args);
// Since the process ID is passed through the command line, we want to make sure that we don't exit before the "restarter"
// process has a chance to open the handle to our process, and that it doesn't wait for the termination of an unrelated
// process which happened to have the same process ID.
TimeoutUtil.sleep(500);
}
use of com.sun.jna.Pointer in project intellij-community by JetBrains.
the class Win7TaskBar method getHandle.
private static WinDef.HWND getHandle(IdeFrame frame) {
try {
ComponentPeer peer = ((Component) frame).getPeer();
Method getHWnd = peer.getClass().getMethod("getHWnd");
return new WinDef.HWND(new Pointer((Long) getHWnd.invoke(peer)));
} catch (Throwable e) {
LOG.error(e);
return null;
}
}
use of com.sun.jna.Pointer in project intellij-community by JetBrains.
the class LibNotifyWrapper method notify.
@Override
public void notify(@NotNull String name, @NotNull String title, @NotNull String description) {
synchronized (myLock) {
if (!myDisposed) {
Pointer notification = myLibNotify.notify_notification_new(title, description, myIcon);
myLibNotify.notify_notification_show(notification, null);
}
}
}
Aggregations