Search in sources :

Example 31 with Pointer

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;
}
Also used : SERVICE_FAILURE_ACTIONS(com.sun.jna.platform.win32.Winsvc.SERVICE_FAILURE_ACTIONS) Pointer(com.sun.jna.Pointer)

Example 32 with Pointer

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;
}
Also used : HDC(com.sun.jna.platform.win32.WinDef.HDC) HWND(com.sun.jna.platform.win32.WinDef.HWND) PIXELFORMATDESCRIPTOR(com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR) Pointer(com.sun.jna.Pointer) HGLRCByReference(com.sun.jna.platform.win32.WinDef.HGLRCByReference) Function(com.sun.jna.Function) HGLRCByReference(com.sun.jna.platform.win32.WinDef.HGLRCByReference)

Example 33 with Pointer

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);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) ArrayList(java.util.ArrayList) Pointer(com.sun.jna.Pointer) WString(com.sun.jna.WString) WinDef(com.sun.jna.platform.win32.WinDef) File(java.io.File)

Example 34 with Pointer

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;
    }
}
Also used : Pointer(com.sun.jna.Pointer) Method(java.lang.reflect.Method) ComponentPeer(java.awt.peer.ComponentPeer)

Example 35 with Pointer

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

Aggregations

Pointer (com.sun.jna.Pointer)152 PointerByReference (com.sun.jna.ptr.PointerByReference)31 Test (org.junit.Test)31 Memory (com.sun.jna.Memory)23 File (java.io.File)21 ByteBuffer (java.nio.ByteBuffer)18 NativeLong (com.sun.jna.NativeLong)17 IntByReference (com.sun.jna.ptr.IntByReference)17 BufferedImage (java.awt.image.BufferedImage)15 FileInputStream (java.io.FileInputStream)11 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)8 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)8 DirectBuffer (sun.nio.ch.DirectBuffer)8 HCONV (com.sun.jna.platform.win32.Ddeml.HCONV)7 ConnectHandler (com.sun.jna.platform.win32.DdemlUtil.ConnectHandler)7 IDdeConnection (com.sun.jna.platform.win32.DdemlUtil.IDdeConnection)7 StandaloneDdeClient (com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 IOException (java.io.IOException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7