コード例 #1
0
ファイル: Kernel32Utils.java プロジェクト: petere/jenkins
  /** Given the process handle, waits for its completion and returns the exit code. */
  public static int waitForExitProcess(Pointer hProcess) throws InterruptedException {
    while (true) {
      if (Thread.interrupted()) throw new InterruptedException();

      Kernel32.INSTANCE.WaitForSingleObject(hProcess, 1000);
      IntByReference exitCode = new IntByReference();
      exitCode.setValue(-1);
      Kernel32.INSTANCE.GetExitCodeProcess(hProcess, exitCode);

      int v = exitCode.getValue();
      if (v != Kernel32.STILL_ACTIVE) {
        return v;
      }
    }
  }
コード例 #2
0
ファイル: User32Util.java プロジェクト: wolftobias/jna
 public static final HWND createWindowEx(
     final int exStyle,
     final String className,
     final String windowName,
     final int style,
     final int x,
     final int y,
     final int width,
     final int height,
     final HWND parent,
     final HMENU menu,
     final HINSTANCE instance,
     final LPVOID param) {
   final HWND hWnd =
       User32.INSTANCE.CreateWindowEx(
           exStyle,
           new WString(className),
           windowName,
           style,
           x,
           y,
           width,
           height,
           parent,
           menu,
           instance,
           param);
   if (hWnd == null) throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
   return hWnd;
 }
コード例 #3
0
ファイル: Advapi32UtilTest.java プロジェクト: siagung/jna
 public void testGetUserAccount() {
   USER_INFO_1 userInfo = new USER_INFO_1();
   userInfo.usri1_name = "JNANetapi32TestUser";
   userInfo.usri1_password = "******";
   userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
   // ignore test if not able to add user (need to be administrator to do this).
   if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
     return;
   }
   try {
     HANDLEByReference phUser = new HANDLEByReference();
     try {
       assertTrue(
           Advapi32.INSTANCE.LogonUser(
               userInfo.usri1_name.toString(),
               null,
               userInfo.usri1_password.toString(),
               WinBase.LOGON32_LOGON_NETWORK,
               WinBase.LOGON32_PROVIDER_DEFAULT,
               phUser));
       Advapi32Util.Account account = Advapi32Util.getTokenAccount(phUser.getValue());
       assertTrue(account.name.length() > 0);
       assertEquals(userInfo.usri1_name.toString(), account.name);
     } finally {
       if (phUser.getValue() != WinBase.INVALID_HANDLE_VALUE) {
         Kernel32.INSTANCE.CloseHandle(phUser.getValue());
       }
     }
   } finally {
     assertEquals(
         LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
   }
 }
コード例 #4
0
ファイル: Kernel32Utils.java プロジェクト: petere/jenkins
 public static File getTempDir() {
   Memory buf = new Memory(1024);
   if (Kernel32.INSTANCE.GetTempPathW(1024, buf) != 0) {
     return new File(buf.getString(0, true));
   } else {
     return null;
   }
 }
コード例 #5
0
ファイル: VariantTest.java プロジェクト: WorkingChen/jna
  public void testVariantDate() {
    SYSTEMTIME lpSystemTime = new SYSTEMTIME();
    Kernel32.INSTANCE.GetLocalTime(lpSystemTime);

    DoubleByReference pvtime = new DoubleByReference();
    OleAuto.INSTANCE.SystemTimeToVariantTime(lpSystemTime, pvtime);

    VARIANT variantDate = new VARIANT(new DATE(pvtime.getValue()));
  }
コード例 #6
0
ファイル: Kernel32Utils.java プロジェクト: petere/jenkins
 /**
  * @param target If relative, resolved against the location of the symlink. If absolute, it's
  *     absolute.
  * @throws UnsatisfiedLinkError If the function is not exported by kernel32. See
  *     http://msdn.microsoft.com/en-us/library/windows/desktop/aa363866(v=vs.85).aspx for
  *     compatibility info.
  */
 public static void createSymbolicLink(File symlink, String target, boolean dirLink)
     throws IOException {
   if (!Kernel32.INSTANCE.CreateSymbolicLinkW(
       new WString(symlink.getPath()),
       new WString(target),
       dirLink ? Kernel32.SYMBOLIC_LINK_FLAG_DIRECTORY : 0)) {
     throw new WinIOException("Failed to create a symlink " + symlink + " to " + target);
   }
 }
コード例 #7
0
  protected static int getPid(Process p) throws Exception {

    if (Platform.isWindows()) {
      Field f = p.getClass().getDeclaredField("handle");
      f.setAccessible(true);
      int pid = Kernel32.INSTANCE.GetProcessId((Long) f.get(p));
      return pid;

    } else if (Platform.isLinux()) {
      Field f = p.getClass().getDeclaredField("pid");
      f.setAccessible(true);
      int pid = (Integer) f.get(p);
      return pid;

    } else {
      throw new Exception("Cannot currently process pid for " + System.getProperty("os.name"));
    }
  }
コード例 #8
0
ファイル: Kernel32Utils.java プロジェクト: petere/jenkins
 public static int getWin32FileAttributes(File file) throws IOException {
   // allow lookup of paths longer than MAX_PATH
   // http://msdn.microsoft.com/en-us/library/aa365247(v=VS.85).aspx
   String canonicalPath = file.getCanonicalPath();
   String path;
   if (canonicalPath.length() < 260) {
     // path is short, use as-is
     path = canonicalPath;
   } else if (canonicalPath.startsWith("\\\\")) {
     // network share
     // \\server\share --> \\?\UNC\server\share
     path = "\\\\?\\UNC\\" + canonicalPath.substring(2);
   } else {
     // prefix, canonical path should be normalized and absolute so this should work.
     path = "\\\\?\\" + canonicalPath;
   }
   return Kernel32.INSTANCE.GetFileAttributesW(new WString(path));
 }
コード例 #9
0
ファイル: User32Util.java プロジェクト: wolftobias/jna
 public static final void destroyWindow(final HWND hWnd) {
   if (!User32.INSTANCE.DestroyWindow(hWnd))
     throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
 }
コード例 #10
0
ファイル: User32Util.java プロジェクト: wolftobias/jna
 public static final int registerWindowMessage(final String lpString) {
   final int messageId = User32.INSTANCE.RegisterWindowMessage(lpString);
   if (messageId == 0) throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
   return messageId;
 }