本文整理汇总了Java中com.sun.jna.platform.win32.Kernel32Util.formatMessageFromLastErrorCode方法的典型用法代码示例。如果您正苦于以下问题:Java Kernel32Util.formatMessageFromLastErrorCode方法的具体用法?Java Kernel32Util.formatMessageFromLastErrorCode怎么用?Java Kernel32Util.formatMessageFromLastErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jna.platform.win32.Kernel32Util
的用法示例。
在下文中一共展示了Kernel32Util.formatMessageFromLastErrorCode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeAsAdmin
import com.sun.jna.platform.win32.Kernel32Util; //导入方法依赖的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: freeSpace
import com.sun.jna.platform.win32.Kernel32Util; //导入方法依赖的package包/类
public static long freeSpace(File file)
{
if (!file.isDirectory() || !file.exists())
return -2;
WinNT.LARGE_INTEGER.ByReference lpTotalNumberOfFreeBytes = new WinNT.LARGE_INTEGER.ByReference();
lpTotalNumberOfFreeBytes.clear();
boolean ret = Kernel32.INSTANCE.GetDiskFreeSpaceEx(file.getPath(),
null, null, lpTotalNumberOfFreeBytes);
if (ret)
return lpTotalNumberOfFreeBytes.getValue();
else
{
String s = Kernel32Util
.formatMessageFromLastErrorCode(Kernel32.INSTANCE
.GetLastError());
log.severe("error in File.freeSpace getting for \""
+ file.getPath() + "\" " + s);
}
return -1;
}
示例3: totalSpace
import com.sun.jna.platform.win32.Kernel32Util; //导入方法依赖的package包/类
public static long totalSpace(File file)
{
if (!file.isDirectory() || !file.exists())
return -2;
WinNT.LARGE_INTEGER.ByReference lpTotalNumberOfBytes = new WinNT.LARGE_INTEGER.ByReference();
lpTotalNumberOfBytes.clear();
boolean ret = Kernel32.INSTANCE.GetDiskFreeSpaceEx(file.getPath(),
null, lpTotalNumberOfBytes, null);
if (ret)
return lpTotalNumberOfBytes.getValue();
else
{
String s = Kernel32Util
.formatMessageFromLastErrorCode(Kernel32.INSTANCE
.GetLastError());
log.severe("error in File.totalSpace getting for \""
+ file.getPath() + "\" " + s);
}
return -1;
}
示例4: msync
import com.sun.jna.platform.win32.Kernel32Util; //导入方法依赖的package包/类
public static void msync(RandomAccessFile raf, long addr, long length)
throws IOException {
int retry = 0;
boolean success;
int lastError = 0;
// FlushViewOfFile can fail with ERROR_LOCK_VIOLATION if the memory system is writing dirty
// pages to disk. As there is no way to synchronize the flushing then we retry a limited
// number of times.
do {
success = KERNEL_32.FlushViewOfFile(new Pointer(addr), new SIZE_T(length));
if (success || (lastError = KERNEL_32.GetLastError()) != ERROR_LOCK_VIOLATION)
break;
retry++;
} while (retry < 3);
if (success) {
// Finally calls FlushFileBuffers
raf.getChannel().force(false);
} else {
throw new IOException(Kernel32Util.formatMessageFromLastErrorCode(lastError));
}
}
示例5: Win32Process
import com.sun.jna.platform.win32.Kernel32Util; //导入方法依赖的package包/类
/**
* creates a new Win32 Process given a process id
* @param pid the process id that describes this process
* @throws IOException if something goes wrong with creating the process reference
*/
public Win32Process(int pid) throws IOException
{
handle = Kernel32.INSTANCE.OpenProcess(
0x0400 | /* PROCESS_QUERY_INFORMATION */
0x0800 | /* PROCESS_SUSPEND_RESUME */
0x0001 | /* PROCESS_TERMINATE */
0x00100000 /* SYNCHRONIZE */,
false,
pid);
if (handle == null)
throw new IOException("OpenProcess failed: "
+ Kernel32Util.formatMessageFromLastErrorCode(Kernel32.INSTANCE.GetLastError()));
this.pid = pid;
}
示例6: WinProcess
import com.sun.jna.platform.win32.Kernel32Util; //导入方法依赖的package包/类
public WinProcess(int pid_) throws IOException {
this();
this.handle = Kernel32.INSTANCE.OpenProcess(0x0400 | // PROCESS_QUERY_INFORMATION
0x0800 | // PROCESS_SUSPEND_RESUME
0x0001 | // PROCESS_TERMINATE
0x0200 | // PROCESS_SET_INFORMATION
0x00100000, // SYNCHRONIZE
false, pid_);
if (this.handle == null) {
throw new IOException("OpenProcess failed: " + Kernel32Util.formatMessageFromLastErrorCode(Kernel32.INSTANCE.GetLastError()) + " (pid: " + pid_ + ")");
}
this.pid = pid_;
}
示例7: win32ErrorIOException
import com.sun.jna.platform.win32.Kernel32Util; //导入方法依赖的package包/类
/**
* returns an IOException exception with a Java-style error report from native implementation.
*
* @param functionName The name of the native function the call has failed.
*/
private static IOException win32ErrorIOException(final String functionName) {
final int err = Kernel32.INSTANCE.GetLastError();
final String mess = Kernel32Util.formatMessageFromLastErrorCode(err);
return new IOException(functionName + " error=" + err + ", " + mess);
}