本文整理汇总了Java中com.sun.jna.Memory.getByte方法的典型用法代码示例。如果您正苦于以下问题:Java Memory.getByte方法的具体用法?Java Memory.getByte怎么用?Java Memory.getByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jna.Memory
的用法示例。
在下文中一共展示了Memory.getByte方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIcon
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Gets the icon that corresponds to a given icon handler.
*
* @param hIcon
* Handler to the icon to get
* @return The icon that corresponds to a given icon handler
*/
public static BufferedImage getIcon(final HICON hIcon) {
final int width = ICON_SIZE;
final int height = ICON_SIZE;
final short depth = ICON_DEPTH;
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
final Memory lpBitsColor = new Memory(width * height * depth / ICON_BYTE_SIZE);
final Memory lpBitsMask = new Memory(width * height * depth / ICON_BYTE_SIZE);
final BITMAPINFO info = new BITMAPINFO();
final BITMAPINFOHEADER hdr = new BITMAPINFOHEADER();
info.bmiHeader = hdr;
hdr.biWidth = width;
hdr.biHeight = height;
hdr.biPlanes = 1;
hdr.biBitCount = depth;
hdr.biCompression = WinGDI.BI_RGB;
final HDC hDC = User32.INSTANCE.GetDC(null);
final ICONINFO piconinfo = new ICONINFO();
User32.INSTANCE.GetIconInfo(hIcon, piconinfo);
GDI32.INSTANCE.GetDIBits(hDC, piconinfo.hbmColor, 0, height, lpBitsColor, info, WinGDI.DIB_RGB_COLORS);
GDI32.INSTANCE.GetDIBits(hDC, piconinfo.hbmMask, 0, height, lpBitsMask, info, WinGDI.DIB_RGB_COLORS);
int r, g, b, a, argb;
int x = 0, y = height - 1;
for (int i = 0; i < lpBitsColor.size(); i = i + 3) {
b = lpBitsColor.getByte(i) & 0xFF;
g = lpBitsColor.getByte(i + 1) & 0xFF;
r = lpBitsColor.getByte(i + 2) & 0xFF;
a = 0xFF - lpBitsMask.getByte(i) & 0xFF;
argb = a << 24 | r << 16 | g << 8 | b;
image.setRGB(x, y, argb);
x = (x + 1) % width;
if (x == 0) {
y--;
}
}
User32.INSTANCE.ReleaseDC(null, hDC);
GDI32.INSTANCE.DeleteObject(piconinfo.hbmColor);
GDI32.INSTANCE.DeleteObject(piconinfo.hbmMask);
return image;
}
示例2: getCurrentUsername
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* This function returns the Username associated with the workstation's or server's ID where this function is executed.<br>
*
* @return username
*/
public static String getCurrentUsername() {
Memory retUserNameMem = new Memory(NotesConstants.MAXUSERNAME+1);
short result = NotesNativeAPI.get().SECKFMGetUserName(retUserNameMem);
NotesErrorUtils.checkResult(result);
int userNameLength = 0;
for (int i=0; i<retUserNameMem.size(); i++) {
userNameLength = i;
if (retUserNameMem.getByte(i) == 0) {
break;
}
}
String userName = NotesStringUtils.fromLMBCS(retUserNameMem, userNameLength);
return userName;
}
示例3: switchToId
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* This function switches to the specified ID file and returns the user name associated with it.<br>
* <br>
* Multiple passwords are not supported.<br>
* <br>
* NOTE: This function should only be used in a C API stand alone application.
*
* @param idPath path to the ID file that is to be switched to
* @param password password of the ID file that is to be switched to
* @param dontSetEnvVar If specified, the notes.ini file (either ServerKeyFileName or KeyFileName) is modified to reflect the ID change.
* @return user name, in the ID file that is to be switched to
*/
public static String switchToId(String idPath, String password, boolean dontSetEnvVar) {
Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true);
Memory passwordMem = NotesStringUtils.toLMBCS(password, true);
Memory retUserNameMem = new Memory(NotesConstants.MAXUSERNAME+1);
short result = NotesNativeAPI.get().SECKFMSwitchToIDFile(idPathMem, passwordMem, retUserNameMem,
NotesConstants.MAXUSERNAME, dontSetEnvVar ? NotesConstants.fKFM_switchid_DontSetEnvVar : 0, null);
NotesErrorUtils.checkResult(result);
int userNameLength = 0;
for (int i=0; i<retUserNameMem.size(); i++) {
userNameLength = i;
if (retUserNameMem.getByte(i) == 0) {
break;
}
}
String userName = NotesStringUtils.fromLMBCS(retUserNameMem, userNameLength);
return userName;
}
示例4: getNullTerminatedLength
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Scans the Memory object for null values
*
* @param in memory
* @return number of bytes before null byte in memory
*/
public static int getNullTerminatedLength(Memory in) {
int textLen = (int) in.size();
//search for terminating null character
for (int i=0; i<textLen; i++) {
byte b = in.getByte(i);
if (b==0) {
textLen = i;
break;
}
}
return textLen;
}
示例5: _getUserIdFromVault
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Internal helper method to fetch the ID from the ID vault.
*
* @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format
* @param password Password to id file being uploaded to the vault
* @param idPath if not null, path to where the download ID file should be created or overwritten
* @param rethKFC64 if not null, returns the hKFC handle to the in-memory id for 64 bit
* @param rethKFC32 if not null, returns the hKFC handle to the in-memory id for 32 bit
* @param serverName Name of server to contact
* @return the vault server name
* @throws NotesError in case of problems, e.g. ERR 22792 Wrong Password
*/
private static String _getUserIdFromVault(String userName, String password, String idPath, LongByReference rethKFC64, IntByReference rethKFC32, String serverName) {
String userNameCanonical = NotesNamingUtils.toCanonicalName(userName);
Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true);
Memory passwordMem = NotesStringUtils.toLMBCS(password, true);
Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true);
Memory serverNameMem = new Memory(NotesConstants.MAXPATH);
{
Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true);
if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) {
throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)");
}
if (serverNameParamMem!=null) {
byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size());
serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length);
}
else {
serverNameMem.setByte(0, (byte) 0);
}
}
short result;
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().SECidfGet(userNameCanonicalMem, passwordMem, idPathMem, rethKFC64, serverNameMem, 0, (short) 0, null);
}
else {
result = NotesNativeAPI32.get().SECidfGet(userNameCanonicalMem, passwordMem, idPathMem, rethKFC32, serverNameMem, 0, (short) 0, null);
}
NotesErrorUtils.checkResult(result);
int vaultServerNameLength = 0;
for (int i=0; i<serverNameMem.size(); i++) {
vaultServerNameLength = i;
if (serverNameMem.getByte(i) == 0) {
break;
}
}
String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength);
return vaultServerName;
}
示例6: syncUserIdWithVault
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Will open the ID file name provided, locate a vault server, synch the ID file contents to the vault,
* then return the synched content. If successful the vault server name is returned.
* @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format
* @param password Password to id file being uploaded to the vault
* @param idPath Path to where the download ID file should be created or overwritten
* @param serverName Name of server to contact
* @return sync result
*/
public static SyncResult syncUserIdWithVault(String userName, String password, String idPath, String serverName) {
String userNameCanonical = NotesNamingUtils.toCanonicalName(userName);
Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true);
Memory passwordMem = NotesStringUtils.toLMBCS(password, true);
Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true);
Memory serverNameMem = new Memory(NotesConstants.MAXPATH);
{
Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true);
if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) {
throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)");
}
if (serverNameParamMem!=null) {
byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size());
serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length);
}
else {
serverNameMem.setByte(0, (byte) 0);
}
}
LongByReference phKFC64 = new LongByReference();
IntByReference phKFC32 = new IntByReference();
IntByReference retdwFlags = new IntByReference();
short result;
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().SECKFMOpen (phKFC64, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null);
}
else {
result = NotesNativeAPI32.get().SECKFMOpen (phKFC32, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null);
}
NotesErrorUtils.checkResult(result);
try {
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().SECidfSync(userNameCanonicalMem, passwordMem, idPathMem, phKFC64, serverNameMem, 0, (short) 0, null, retdwFlags);
}
else {
result = NotesNativeAPI32.get().SECidfSync(userNameCanonicalMem, passwordMem, idPathMem, phKFC32, serverNameMem, 0, (short) 0, null, retdwFlags);
}
NotesErrorUtils.checkResult(result);
}
finally {
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().SECKFMClose(phKFC64, NotesConstants.SECKFM_close_WriteIdFile, 0, null);
}
else {
result = NotesNativeAPI32.get().SECKFMClose(phKFC32, NotesConstants.SECKFM_close_WriteIdFile, 0, null);
}
NotesErrorUtils.checkResult(result);
}
NotesErrorUtils.checkResult(result);
int vaultServerNameLength = 0;
for (int i=0; i<serverNameMem.size(); i++) {
vaultServerNameLength = i;
if (serverNameMem.getByte(i) == 0) {
break;
}
}
String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength);
SyncResult syncResult = new SyncResult(vaultServerName, retdwFlags.getValue());
return syncResult;
}
示例7: constructNetPath
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Constructs a network path of a database (server!!path with proper encoding)
*
* @param server server or null
* @param filePath filepath
* @return LMBCS encoded path
*/
private static Memory constructNetPath(String server, String filePath) {
if (server==null)
server = "";
if (filePath==null)
throw new NullPointerException("filePath is null");
server = NotesNamingUtils.toCanonicalName(server);
String idUserName = IDUtils.getCurrentUsername();
boolean isOnServer = IDUtils.isOnServer();
if (!"".equals(server)) {
if (isOnServer) {
String serverCN = NotesNamingUtils.toCommonName(server);
String currServerCN = NotesNamingUtils.toCommonName(idUserName);
if (serverCN.equalsIgnoreCase(currServerCN)) {
//switch to "" as servername if server points to the server the API is running on
server = "";
}
}
}
Memory dbServerLMBCS = NotesStringUtils.toLMBCS(server, true);
Memory dbFilePathLMBCS = NotesStringUtils.toLMBCS(filePath, true);
Memory retFullNetPath = new Memory(NotesConstants.MAXPATH);
short result = NotesNativeAPI.get().OSPathNetConstruct(null, dbServerLMBCS, dbFilePathLMBCS, retFullNetPath);
NotesErrorUtils.checkResult(result);
//reduce length of retDbPathName
int newLength = 0;
for (int i=0; i<retFullNetPath.size(); i++) {
byte b = retFullNetPath.getByte(i);
if (b==0) {
newLength = i;
break;
}
}
byte[] retFullNetPathArr = retFullNetPath.getByteArray(0, newLength);
Memory reducedFullNetPathMem = new Memory(newLength+1);
reducedFullNetPathMem.write(0, retFullNetPathArr, 0, retFullNetPathArr.length);
reducedFullNetPathMem.setByte(newLength, (byte) 0);
return reducedFullNetPathMem;
}
示例8: stopWindowsProcessWMClosed
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Sends {@code WM_CLOSE} to the specified Windows {@link Process}.
*
* @param processInfo the {@link ProcessInfo} referencing the
* {@link Process} to send to.
* @return {@code true} if {@code WM_CLOSE} was sent, {@code false}
* otherwise.
*/
protected boolean stopWindowsProcessWMClosed(@Nonnull ProcessInfo processInfo) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(
"Attempting to stop timed out process \"{}\" ({}) with WM_CLOSE",
processInfo.getName(),
processInfo.getPID()
);
}
HANDLE hProc = Kernel32.INSTANCE.OpenProcess(
Kernel32.SYNCHRONIZE | Kernel32.PROCESS_TERMINATE,
false,
processInfo.getPID()
);
if (hProc == null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(
"Failed to get Windows handle for process \"{}\" ({}) during WM_CLOSE",
processInfo.getName(),
processInfo.getPID()
);
}
return false;
}
final Memory posted = new Memory(1);
posted.setByte(0, (byte) 0);
Memory dwPID = new Memory(4);
dwPID.setInt(0, processInfo.getPID());
User32.INSTANCE.EnumWindows(new WNDENUMPROC() {
@Override
public boolean callback(HWND hWnd, Pointer data) {
IntByReference dwID = new IntByReference();
User32.INSTANCE.GetWindowThreadProcessId(hWnd, dwID);
if (dwID.getValue() == data.getInt(0)) {
User32.INSTANCE.PostMessage(hWnd, User32.WM_CLOSE, new WPARAM(0), new LPARAM(0));
posted.setByte(0, (byte) 1);
}
return true;
}
}, dwPID);
Kernel32.INSTANCE.CloseHandle(hProc);
if (LOGGER.isTraceEnabled()) {
if (posted.getByte(0) > 0) {
LOGGER.trace(
"WM_CLOSE sent to process \"{}\" ({}) with PostMessage",
processInfo.getName(),
processInfo.getPID()
);
} else {
LOGGER.trace(
"Can't find any Windows belonging to process \"{}\" ({}), unable to send WM_CLOSE",
processInfo.getName(),
processInfo.getPID()
);
}
}
return posted.getByte(0) > 0;
}
示例9: getValue
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* @return The value of this {@link CFNumberRef} as a {@link Number}.
*/
public Number getValue() {
if (this.getPointer() == null) {
return null;
}
CFNumberType numberType = INSTANCE.CFNumberGetType(this);
Memory value = new Memory(8);
INSTANCE.CFNumberGetValue(this, numberType, value);
switch (numberType) {
case kCFNumberCFIndexType:
case kCFNumberSInt32Type:
return value.getInt(0);
case kCFNumberCGFloatType:
case kCFNumberMaxType:
if (NativeLong.SIZE == 8) {
return value.getDouble(0);
}
return value.getFloat(0);
case kCFNumberCharType:
return (int) value.getChar(0);
case kCFNumberDoubleType:
case kCFNumberFloat64Type:
return value.getDouble(0);
case kCFNumberFloatType:
case kCFNumberFloat32Type:
return value.getFloat(0);
case kCFNumberLongLongType:
case kCFNumberSInt64Type:
return value.getLong(0);
case kCFNumberIntType:
case kCFNumberLongType:
case kCFNumberNSIntegerType:
return value.getNativeLong(0);
case kCFNumberSInt16Type:
case kCFNumberShortType:
return value.getShort(0);
case kCFNumberSInt8Type:
return value.getByte(0);
default:
throw new IllegalStateException("Unimplemented value " + numberType);
}
}