本文整理汇总了Java中com.sun.jna.WString类的典型用法代码示例。如果您正苦于以下问题:Java WString类的具体用法?Java WString怎么用?Java WString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WString类属于com.sun.jna包,在下文中一共展示了WString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeAsAdmin
import com.sun.jna.WString; //导入依赖的package包/类
public static void executeAsAdmin(String command, String args) {
SHELLEXECUTEINFO execInfo = new SHELLEXECUTEINFO();
execInfo.lpFile = new WString(command);
if (args != null) {
execInfo.lpParameters = new WString(args);
}
execInfo.nShow = Shell32X.SW_SHOWDEFAULT;
execInfo.fMask = Shell32X.SEE_MASK_NOCLOSEPROCESS;
execInfo.lpVerb = new WString("runas");
boolean result = Shell32X.INSTANCE.ShellExecuteEx(execInfo);
if (!result) {
int lastError = Kernel32.INSTANCE.GetLastError();
String errorMessage = Kernel32Util.formatMessageFromLastErrorCode(lastError);
throw new RuntimeException("Error performing elevation: " + lastError + ": " + errorMessage + " (apperror=" + execInfo.hInstApp + ")");
}
}
示例2: changeWorkingDir
import com.sun.jna.WString; //导入依赖的package包/类
public boolean changeWorkingDir(String name)
{
File f = new File(name);
String dir;
if (!f.exists() || !f.isDirectory())
{
System.out.println("setWorkingDirectory failed. file not found "
+ name);
return false;
}
else
try
{
dir = f.getCanonicalPath();
}
catch (IOException e)
{
e.printStackTrace();
return false;
}
boolean result = MyKernel32.INSTANCE.SetCurrentDirectoryW(new WString(dir));
if (result)
System.setProperty("user.dir", dir);
return result;
}
示例3: createWindowsProcess
import com.sun.jna.WString; //导入依赖的package包/类
private HWND createWindowsProcess() {
WString windowClass = new WString(APPNAME);
HMODULE hInst = libK.GetModuleHandle("");
WNDCLASSEX wndclass = new WNDCLASSEX();
wndclass.hInstance = hInst;
wndclass.lpfnWndProc = SSHAgent.this;
wndclass.lpszClassName = windowClass;
// register window class
libU.RegisterClassEx(wndclass);
getLastError();
// create new window
HWND winprocess = libU
.CreateWindowEx(
User32.WS_OVERLAPPED,
windowClass,
APPNAME,
0, 0, 0, 0, 0,
null, // WM_DEVICECHANGE contradicts parent=WinUser.HWND_MESSAGE
null, hInst, null);
mutex = libK.CreateMutex(null, false, MUTEX_NAME);
return winprocess;
}
示例4: open
import com.sun.jna.WString; //导入依赖的package包/类
public synchronized MediaInfo open(File file) throws IOException, IllegalArgumentException {
if (!file.isFile() || file.length() < 64 * 1024) {
throw new IllegalArgumentException("Invalid media file: " + file);
}
String path = file.getCanonicalPath();
// on Mac files that contain accents cannot be opened via JNA WString file paths due to encoding differences so we use the buffer interface instead for these files
if (Platform.isMac() && !StandardCharsets.US_ASCII.newEncoder().canEncode(path)) {
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
if (openViaBuffer(raf)) {
throw new IOException("Failed to initialize media info buffer: " + path);
}
}
}
if (0 == MediaInfoLibrary.INSTANCE.Open(handle, new WString(path))) {
// failed to open file
throw new IOException("Failed to open media file: " + path);
}
return this;
}
示例5: mediaInfo
import com.sun.jna.WString; //导入依赖的package包/类
/**
* Extract media information for a particular file.
*
* @param filename name of the file
* @return media information
* @throws MediaInfoParseException if a parse error occurs
*/
public static MediaInfo mediaInfo(String filename) {
MediaInfo result;
LibMediaInfo lib = LibMediaInfo.INSTANCE;
Pointer handle = lib.MediaInfo_New();
if (handle != null) {
try {
int opened = lib.MediaInfo_Open(handle, new WString(filename));
if (opened == 1) {
WString data = lib.MediaInfo_Inform(handle);
lib.MediaInfo_Close(handle);
result = new Parser(data.toString()).parse();
}
else {
result = null;
}
}
finally {
lib.MediaInfo_Delete(handle);
}
}
else {
result = null;
}
return result;
}
示例6: findDevices
import com.sun.jna.WString; //导入依赖的package包/类
boolean findDevices() {
WString pluginName = new WString("Saitek");
dol.DirectOutput_Initialize(pluginName);
DirectOutputLibrary.HRESULT result = dol.DirectOutput_Enumerate((hDevice, pCtc) -> {
devices.add(hDevice);
}, null);
for (Pointer p : devices) {
Memory g = new Memory(16);
DirectOutputLibrary.LPGUID guid = new DirectOutputLibrary.LPGUID(g.getPointer(0));
result = dol.DirectOutput_GetDeviceType(p, guid);
String pseudoGuid = toGuidString(guid.getPointer().getByteArray(0, 16)); // the byte order isn't correct, but we don't care right now
if (X52_PRO.equals(pseudoGuid)) {
System.out.println("Found X52 Pro! Yay!");
x52pro = p;
return true;
}
}
return false;
}
示例7: open
import com.sun.jna.WString; //导入依赖的package包/类
/**
* Open.
*
* @param file
* the file
* @return true, if successful
*/
public boolean open(Path file) throws MediaInfoException {
// create handle
try {
if (handle == null) {
handle = MediaInfoLibrary.INSTANCE.New();
}
}
catch (LinkageError e) {
return false;
}
if (file != null && isLoaded()) {
return MediaInfoLibrary.INSTANCE.Open(handle, new WString(file.toAbsolutePath().toString())) > 0;
}
else {
return false;
}
}
示例8: CryptProtectData
import com.sun.jna.WString; //导入依赖的package包/类
/** @see <a href="http://msdn.microsoft.com/en-us/library/aa380261(VS.85,printer).aspx">Reference</a> */
boolean CryptProtectData(
CryptIntegerBlob pDataIn,
WString szDataDescr,
CryptIntegerBlob pOptionalEntropy,
Pointer pvReserved,
Pointer pPromptStruct,
int dwFlags,
CryptIntegerBlob pDataOut
)/* throws LastErrorException*/;
示例9: CryptUnprotectData
import com.sun.jna.WString; //导入依赖的package包/类
/** @see <a href="http://msdn.microsoft.com/en-us/library/aa380882(VS.85,printer).aspx">Reference</a> */
boolean CryptUnprotectData(
CryptIntegerBlob pDataIn,
WString[] ppszDataDescr,
CryptIntegerBlob pOptionalEntropy,
Pointer pvReserved,
Pointer pPromptStruct,
int dwFlags,
CryptIntegerBlob pDataOut
)/* throws LastErrorException*/;
示例10: main
import com.sun.jna.WString; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException {
Pointer pointer;
System.out.println("running in " + System.getProperty("sun.arch.data.model"));
System.out.println("Loading dll");
autoHotKeyDll lib = (autoHotKeyDll) Native.loadLibrary("AutoHotkey.dll", autoHotKeyDll.class);
System.out.println("initialisation");
lib.ahktextdll(new WString(""), new WString(""), new WString(""));
// Thread.sleep(100);
// lib.addFile(new WString(System.getProperty("user.dir") + "\\lib.ahk"), 1);
// Thread.sleep(1000);
// System.out.println("function call");
// System.out.println("return:" + lib.ahkFunction(new WString("function"),new WString(""),new WString(""),new
// WString(""),new WString(""),new WString(""),new WString(""),new WString(""),new WString(""),new
// WString(""),new WString("")).getString(0));
Thread.sleep(1000);
System.out.println("displaying cbBox");
lib.ahkExec(new WString("Send {Right}"));
Thread.sleep(1000);
}
示例11: getGroupNodeInfo
import com.sun.jna.WString; //导入依赖的package包/类
private ClusterGroupInfo getGroupNodeInfo(Pointer cluster, String groupName)
{
ClusterGroupInfo result = null;
try
{
Pointer hGroup = Clusapi.INSTANCE.OpenClusterGroup(cluster,
new WString(groupName));
if (hGroup == null)
throw new RuntimeException(
"Clusapi call to OpenClusterGroup returned err code "
+ MyKernel32.INSTANCE.GetLastError());
IntByReference lpcchNodeName = new IntByReference();
Memory lpszNodeName = new Memory(256);
lpszNodeName.clear();
lpcchNodeName.setValue(256);
int state = Clusapi.INSTANCE.GetClusterGroupState(hGroup,
lpszNodeName, lpcchNodeName);
String location = lpszNodeName.getString(0, true);
if (state == Clusapi.CLUSTER_GROUP_STATE_UNKNOWN)
_log.severe("unknown group state for group " + groupName
+ " err code " + MyKernel32.INSTANCE.GetLastError());
result = new ClusterGroupInfo(groupName, state, location);
MyKernel32.INSTANCE.CloseHandle(hGroup);
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Error while getting GroupActiveNode", e);
}
return result;
}
示例12: setString
import com.sun.jna.WString; //导入依赖的package包/类
@Override
public void setString(long offset, WString value) {
if (m_sealed)
throw new UnsupportedOperationException();
super.setString(offset, value);
}
示例13: staticOption
import com.sun.jna.WString; //导入依赖的package包/类
public static String staticOption(String option, String value) {
try {
return MediaInfoLibrary.INSTANCE.Option(null, new WString(option), new WString(value)).toString();
} catch (LinkageError e) {
throw new MediaInfoException(e);
}
}
示例14: getProcessesUsing
import com.sun.jna.WString; //导入依赖的package包/类
public static List<Process> getProcessesUsing(File file) {
List<Process> processes = new LinkedList<Process>();
// If the DLL was not present (XP or other OS), do not try to find it again.
if (ourFailed) {
return processes;
}
try {
IntByReference session = new IntByReference();
char[] sessionKey = new char[Win32RestartManager.CCH_RM_SESSION_KEY + 1];
int error = Win32RestartManager.INSTANCE.RmStartSession(session, 0, sessionKey);
if (error != 0) {
Runner.logger.warn("Unable to start restart manager session");
return processes;
}
StringArray resources = new StringArray(new WString[]{new WString(file.toString())});
error = Win32RestartManager.INSTANCE.RmRegisterResources(session.getValue(), 1, resources, 0, Pointer.NULL, 0, null);
if (error != 0) {
Runner.logger.warn("Unable to register restart manager resource " + file.getAbsolutePath());
return processes;
}
IntByReference procInfoNeeded = new IntByReference();
Win32RestartManager.RmProcessInfo info = new Win32RestartManager.RmProcessInfo();
Win32RestartManager.RmProcessInfo[] infos = (Win32RestartManager.RmProcessInfo[])info.toArray(MAX_PROCESSES);
IntByReference procInfo = new IntByReference(infos.length);
error = Win32RestartManager.INSTANCE.RmGetList(session.getValue(), procInfoNeeded, procInfo, info, new LongByReference());
if (error != 0) {
Runner.logger.warn("Unable to get the list of processes using " + file.getAbsolutePath());
return processes;
}
for (int i = 0; i < procInfo.getValue(); i++) {
processes.add(new Process(infos[i].Process.dwProcessId, new String(infos[i].strAppName).trim()));
}
Win32RestartManager.INSTANCE.RmEndSession(session.getValue());
} catch (Throwable t) {
// Best effort approach, if no DLL is found ignore.
ourFailed = true;
}
return processes;
}
示例15: encode
import com.sun.jna.WString; //导入依赖的package包/类
public byte[] encode(File file) {
byte[] path = new byte[file.getAbsolutePath().length() * 3 + 1];
int pathLength = libC.wcstombs(path, new WString(file.getAbsolutePath()), path.length);
if (pathLength < 0) {
throw new RuntimeException(String.format("Could not encode file path '%s'.", file.getAbsolutePath()));
}
byte[] zeroTerminatedByteArray = new byte[pathLength + 1];
System.arraycopy(path, 0, zeroTerminatedByteArray, 0, pathLength);
zeroTerminatedByteArray[pathLength] = 0;
return zeroTerminatedByteArray;
}