Package com.sun.jna.examples.win32.WinNT

Examples of com.sun.jna.examples.win32.WinNT.HANDLE


        String pPrinterName = "HP Color LaserJet CM4730 MFP PCL 6";
        HANDLEByReference phPrinter = new HANDLEByReference();
        Winspool.INSTANCE.OpenPrinter(pPrinterName, phPrinter, null);

        // Get change notification handle for the printer
        HANDLE chgObject = Winspool.INSTANCE
                .FindFirstPrinterChangeNotification(phPrinter.getValue(),
                        Winspool.PRINTER_CHANGE_JOB, 0, null);

        if (chgObject != null) {
            while (true) {
View Full Code Here


    public void testSHGetKnownFolderPath()
    {
        int flags = ShlObj.KNOWN_FOLDER_FLAG.NONE.getFlag();
        PointerByReference outPath = new PointerByReference();
        HANDLE token = null;
        GUID guid = KnownFolders.FOLDERID_Fonts;
        HRESULT hr = Shell32.INSTANCE.SHGetKnownFolderPath(guid, flags, token, outPath);

        Ole32.INSTANCE.CoTaskMemFree(outPath.getValue());
View Full Code Here

     */
    public static String getKnownFolderPath(GUID guid) throws Win32Exception
    {
        int flags = ShlObj.KNOWN_FOLDER_FLAG.NONE.getFlag();
        PointerByReference outPath = new PointerByReference();
        HANDLE token = null;
        HRESULT hr = Shell32.INSTANCE.SHGetKnownFolderPath(guid, flags, token, outPath);

        if (!W32Errors.SUCCEEDED(hr.intValue()))
        {
            throw new Win32Exception(hr);
View Full Code Here

      FileWriter fw = new FileWriter(tmp);
      fw.append(expected);
      fw.close();

      HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_READ, WinNT.FILE_SHARE_READ,
          new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
      assertFalse(hFile == WinBase.INVALID_HANDLE_VALUE);

      Memory m = new Memory(2048);
      IntByReference lpNumberOfBytesRead = new IntByReference(0);
View Full Code Here

    public void testSetHandleInformation() throws IOException {
      File tmp = File.createTempFile("testSetHandleInformation", "jna");
      tmp.deleteOnExit();

      HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_READ, WinNT.FILE_SHARE_READ,
          new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
      assertFalse(hFile == WinBase.INVALID_HANDLE_VALUE);

      assertTrue(Kernel32.INSTANCE.SetHandleInformation(hFile, WinBase.HANDLE_FLAG_PROTECT_FROM_CLOSE, 0));
      assertTrue(Kernel32.INSTANCE.CloseHandle(hFile));
View Full Code Here

    }

    public void testTerminateProcess() throws IOException {
      File tmp = File.createTempFile("testTerminateProcess", "jna");
      tmp.deleteOnExit();
      HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_READ, WinNT.FILE_SHARE_READ,
          new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);

      assertFalse(Kernel32.INSTANCE.TerminateProcess(hFile, 1));
      assertEquals(WinError.ERROR_INVALID_HANDLE, Kernel32.INSTANCE.GetLastError());
      assertTrue(Kernel32.INSTANCE.CloseHandle(hFile));
View Full Code Here

    public void testGetSetFileTime() throws IOException {
        File tmp = File.createTempFile("testGetSetFileTime", "jna");
        tmp.deleteOnExit();

        HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_WRITE, WinNT.FILE_SHARE_WRITE,
          new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
      assertFalse(hFile == WinBase.INVALID_HANDLE_VALUE);

        WinBase.FILETIME.ByReference creationTime = new WinBase.FILETIME.ByReference();
        WinBase.FILETIME.ByReference accessTime = new WinBase.FILETIME.ByReference();
View Full Code Here

        assertTrue(reader.readLine().matches("E\\s*=\\s*Z"));
        reader.close();
    }

    public final void testCreateRemoteThread() throws IOException {
      HANDLE hThrd = Kernel32.INSTANCE.CreateRemoteThread(null, null, 0, null, null, null, null);
      assertNull(hThrd);
      assertEquals(Kernel32.INSTANCE.GetLastError(), WinError.ERROR_INVALID_HANDLE);
    }
View Full Code Here

      ByteBuffer bufSrc = ByteBuffer.allocateDirect(4);
      bufSrc.put(new byte[]{5,10,15,20});
      Pointer ptrSrc = Native.getDirectBufferPointer(bufSrc);
      Pointer ptrDest = Native.getDirectBufferPointer(bufDest);
     
      HANDLE selfHandle = kernel.GetCurrentProcess();
      kernel.WriteProcessMemory(selfHandle, ptrDest, ptrSrc, 3, null);//Write only the first three
     
    assertEquals(bufDest.get(0),5);
      assertEquals(bufDest.get(1),10);
      assertEquals(bufDest.get(2),15);
View Full Code Here

      ByteBuffer bufDest = ByteBuffer.allocateDirect(4);
      bufDest.put(new byte[]{0,1,2,3});
      Pointer ptrSrc = Native.getDirectBufferPointer(bufSrc);
      Pointer ptrDest = Native.getDirectBufferPointer(bufDest);
     
      HANDLE selfHandle = kernel.GetCurrentProcess();
      kernel.ReadProcessMemory(selfHandle, ptrSrc, ptrDest, 3, null);//Read only the first three
     
    assertEquals(bufDest.get(0),5);
      assertEquals(bufDest.get(1),10);
      assertEquals(bufDest.get(2),15);
View Full Code Here

TOP

Related Classes of com.sun.jna.examples.win32.WinNT.HANDLE

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.