當前位置: 首頁>>代碼示例>>Java>>正文


Java NativeLibrary.getInstance方法代碼示例

本文整理匯總了Java中com.sun.jna.NativeLibrary.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java NativeLibrary.getInstance方法的具體用法?Java NativeLibrary.getInstance怎麽用?Java NativeLibrary.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.jna.NativeLibrary的用法示例。


在下文中一共展示了NativeLibrary.getInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Saitek

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public Saitek(File... libraryPath) {
  // try paths individually
  for (File f : libraryPath) {
    String path = f.toString();
    if (path.length() > 0) {
      // System.out.println("Using jna.library.path " + path);
      System.setProperty("jna.library.path", path);
    }
    try {
      NativeLibrary.getInstance(DirectOutputLibrary.JNA_LIBRARY_NAME);
      dol = (DirectOutputLibrary) Native.loadLibrary(DirectOutputLibrary.JNA_LIBRARY_NAME, DirectOutputLibrary.class);
    } catch (UnsatisfiedLinkError err) {
      System.err.println("Unable to load DirectOutput.dll from " + f + " (running on " + System.getProperty("os.name") + "-" + System.getProperty("os.version") 
              + "-" + System.getProperty("os.arch") + "\nContinuuing...");
      continue;
    }
    System.out.println("Loaded library from " + f);
    break;
  }
  if (dol == null) {
    throw new IllegalArgumentException("Unable to load DirectOutput.dll from the paths provided");
  }
  executor = Executors.newSingleThreadExecutor();
  executor.submit(this::init);
}
 
開發者ID:beders,項目名稱:saitek-lcd,代碼行數:26,代碼來源:Saitek.java

示例2: getWin32NativeLibrary

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
private static NativeLibrary getWin32NativeLibrary(String name) {
    //
    // gstreamer on win32 names the dll files one of foo.dll, libfoo.dll and libfoo-0.dll
    //
    String[] nameFormats = { 
        "%s", "lib%s", "lib%s-0",                   
    };
    for (int i = 0; i < nameFormats.length; ++i) {
        try {
            return NativeLibrary.getInstance(String.format(nameFormats[i], name));
        } catch (UnsatisfiedLinkError ex) {                
            continue;
        }
    }
    throw new UnsatisfiedLinkError("Could not load library " + name);
}
 
開發者ID:armouroflight,項目名稱:java-gobject,代碼行數:17,代碼來源:GNative.java

示例3: isAeroEnabled

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static boolean isAeroEnabled(){		
    if( HearthHelper.getOSName().equals("win") && DWM == null){
    	try{
    		DWM = NativeLibrary.getInstance("dwmapi");
    	} catch(Throwable e) {}
    }
    
    boolean dwmEnabled = false;
    
       if(DWM != null){
       	boolean[] bool = { false };
       	Object[] args = { bool };
       	Function DwmIsCompositionEnabled = DWM.getFunction("DwmIsCompositionEnabled");
       	HRESULT result = (HRESULT) DwmIsCompositionEnabled.invoke(HRESULT.class, args);
       	boolean success = result.intValue()==0;
       	
       	if(success && bool[0]){
       		dwmEnabled = true;
       	}
       }  

    return dwmEnabled;
}
 
開發者ID:megablue,項目名稱:Hearthtracker,代碼行數:24,代碼來源:HearthRobot.java

示例4: openLib

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static WinscardLibInfo openLib() {
	String libraryName = Platform.isWindows() ? WINDOWS_PATH : Platform.isMac() ? MAC_PATH : PCSC_PATH;
	HashMap<String, Object> options = new HashMap<String, Object>();
	if (Platform.isWindows()) {
		options.put(Library.OPTION_FUNCTION_MAPPER, new WindowsFunctionMapper());
	} else if (Platform.isMac()) {
		options.put(Library.OPTION_FUNCTION_MAPPER, new MacFunctionMapper());
	}
	WinscardLibrary lib = (WinscardLibrary) Native.loadLibrary(libraryName, WinscardLibrary.class, options);
	NativeLibrary nativeLibrary = NativeLibrary.getInstance(libraryName);
	// SCARD_PCI_* is #defined to the following symbols (both pcsclite and winscard)
	ScardIoRequest SCARD_PCI_T0 = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardT0Pci"));
	ScardIoRequest SCARD_PCI_T1 = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardT1Pci"));
	ScardIoRequest SCARD_PCI_RAW = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardRawPci"));
	SCARD_PCI_T0.read();
	SCARD_PCI_T1.read();
	SCARD_PCI_RAW.read();
	SCARD_PCI_T0.setAutoSynch(false);
	SCARD_PCI_T1.setAutoSynch(false);
	SCARD_PCI_RAW.setAutoSynch(false);
	return new WinscardLibInfo(lib, SCARD_PCI_T0, SCARD_PCI_T1, SCARD_PCI_RAW);
}
 
開發者ID:jnasmartcardio,項目名稱:jnasmartcardio,代碼行數:23,代碼來源:Winscard.java

示例5: getNativeLibrary

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static synchronized NativeLibrary getNativeLibrary(String name) {
    if (!Platform.isWindows())
        return NativeLibrary.getInstance(name);
    for (String format : windowsNameFormats)
        try {
            return NativeLibrary.getInstance(String.format(format, name));
        } catch (UnsatisfiedLinkError ex) {
            continue;
        }
    throw new UnsatisfiedLinkError("Could not load library: " + name);
}
 
開發者ID:gstreamer-java,項目名稱:gstreamer1.x-java,代碼行數:12,代碼來源:GNative.java

示例6: loadLibrary

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static NativeLibrary loadLibrary(String library) {
	try {
		return NativeLibrary.getInstance(saveLibrary(library));
	} catch (IOException e) {
		return NativeLibrary.getInstance(library);
	}
}
 
開發者ID:bskaggs,項目名稱:jjq,代碼行數:8,代碼來源:NativeLoader.java

示例7: getNativeLibrary

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static synchronized NativeLibrary getNativeLibrary(String name) {
    for (String format : nameFormats)
        try {
            return NativeLibrary.getInstance(String.format(format, name));
        } catch (UnsatisfiedLinkError ex) {
            continue;
        }
    throw new UnsatisfiedLinkError("Could not load library: " + name);
}
 
開發者ID:gstreamer-java,項目名稱:gst1-java-core,代碼行數:10,代碼來源:GNative.java

示例8: dynLoad

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
@Primitive("dyn.load")
public static ListVector dynLoad(String libraryPath, SEXP local, SEXP now, SEXP dllPath) {

  NativeLibrary library = NativeLibrary.getInstance(libraryPath);
  
  ListVector.NamedBuilder result = new ListVector.NamedBuilder();

  result.add("name", library.getName());
  result.add("path", libraryPath);
  result.add("dynamicLookup", LogicalVector.TRUE);
  result.add("handle", new ExternalExp<NativeLibrary>(library));
  result.add("info", "something here");
  result.setAttribute(Symbols.CLASS, StringVector.valueOf("DLLInfo"));
  return result.build();
}
 
開發者ID:bedatadriven,項目名稱:renjin-statet,代碼行數:16,代碼來源:Native.java

示例9: init

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static synchronized void init() {
  NativeLibrary libcLibrary = NativeLibrary.getInstance(Platform.C_LIBRARY_NAME);

  // We kill subprocesses by sending SIGHUP to our process group; we want our subprocesses to die
  // on SIGHUP while we ourselves stay around.  We can't just set SIGHUP to SIG_IGN, because
  // subprocesses would inherit the SIG_IGN signal disposition and be immune to the SIGHUP we
  // direct toward the process group.  We need _some_ signal handler that does nothing --- i.e.,
  // acts like SIG_IGN --- but that doesn't kill its host process.  When we spawn a subprocess,
  // the kernel replaces any signal handler that is not SIG_IGN with SIG_DFL, automatically
  // creating the signal handler configuration we want.
  //
  // getpid might seem like a strange choice of signal handler, but consider the following:
  //
  //   1) on all supported ABIs, calling a function that returns int as if it returned void is
  //      harmless --- the return value is stuffed into a register (for example, EAX on x86
  //      32-bit) that the caller ignores (EAX is caller-saved),
  //
  //   2) on all supported ABIs, calling a function with extra arguments is safe --- the callee
  //      ignores the extra arguments, which are passed either in caller-saved registers or in
  //      stack locations that the caller [1] cleans up upon return,
  //
  //   3) getpid is void(*)(int); signal handlers are void(*)(int), and
  //
  //   4) getpid is async-signal-safe according to POSIX.
  //
  // Therefore, it is safe to set getpid _as_ a signal handler.  It does nothing, exactly as we
  // want, and gets reset to SIG_DFL in subprocesses.  If we were a C program, we'd just define a
  // no-op function of the correct signature to use as a handler, but we're using JNA, and while
  // JNA does have the ability to C function pointer to a Java function, it cannot create an
  // async-signal-safe C function, since calls into Java are inherently signal-unsafe.
  //
  // [1] Win32 32-bit x86 stdcall is an exception to this general rule --- because the callee
  //      cleans up its stack --- but we don't run this code on Windows.
  //
  Libc.INSTANCE.signal(Libc.Constants.SIGHUP, libcLibrary.getFunction("getpid"));
  initialized = true;
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:38,代碼來源:BgProcessKiller.java

示例10: JnaNativeLibrary

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public JnaNativeLibrary(JnaNativeInterface nativeInterface, String name,
		Map<String, Object> options) {
	this.nativeInterface = nativeInterface;
	// this is a kludge - but i can't ask for the searchpaths already
	// registered
	for (Iterator<String> it = nativeInterface.getSearchPaths().iterator(); it
			.hasNext();) {
		String path = it.next();
		NativeLibrary.addSearchPath(name, path);
	}
	library = NativeLibrary.getInstance(name, options);
}
 
開發者ID:intarsys,項目名稱:native-c,代碼行數:13,代碼來源:JnaNativeLibrary.java

示例11: onWindows

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static void onWindows() {
	// Windows taskbar fix: provideAppUserModelID
	try {
		NativeLibrary lib = NativeLibrary.getInstance("shell32");
	    Function function = lib.getFunction("SetCurrentProcessExplicitAppUserModelID");
	    Object[] args = {new WString(APPID)}; 
	    function.invokeInt(args);
	} catch (Error e) {
	    return;
	} catch (Exception x) {
		return;
	}
}
 
開發者ID:chms,項目名稱:jdotxt,代碼行數:14,代碼來源:Jdotxt.java

示例12: doLoadLibrary

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
private static NativeLibrary doLoadLibrary(String name) {
	return NativeLibrary.getInstance(name);
}
 
開發者ID:google,項目名稱:mr4c,代碼行數:4,代碼來源:JnaUtils.java

示例13: load

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
private static void load(String name) {
  NativeLibrary library = NativeLibrary.getInstance(name, LibGmp.class.getClassLoader());
  Native.register(LibGmp.class, library);
  Native.register(SIZE_T_CLASS, library);
}
 
開發者ID:square,項目名稱:jna-gmp,代碼行數:6,代碼來源:LibGmp.java

示例14: getNativeLibrary

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static NativeLibrary getNativeLibrary(String name) {
    if (Platform.isWindows()) {
        return getWin32NativeLibrary(name);
    }
    return NativeLibrary.getInstance(name);
}
 
開發者ID:armouroflight,項目名稱:java-gobject,代碼行數:7,代碼來源:GNative.java

示例15: unload

import com.sun.jna.NativeLibrary; //導入方法依賴的package包/類
public static synchronized void unload(Instance instance) {
	NativeLibrary library = NativeLibrary.getInstance(instance.file.getAbsolutePath());
	library.dispose();
}
 
開發者ID:testobject,項目名稱:visual-scripting,代碼行數:5,代碼來源:FreeTypeLoader.java


注:本文中的com.sun.jna.NativeLibrary.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。