当前位置: 首页>>代码示例>>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;未经允许,请勿转载。