use of com.sun.jna.platform.win32.WinDef.CHAR in project jna by java-native-access.
the class PsapiTest method testGetModuleFileNameEx.
@Test
public void testGetModuleFileNameEx() {
final JFrame w = new JFrame();
try {
w.setVisible(true);
final String searchSubStr = "\\bin\\java";
final HWND hwnd = new HWND(Native.getComponentPointer(w));
final IntByReference pid = new IntByReference();
User32.INSTANCE.GetWindowThreadProcessId(hwnd, pid);
final HANDLE process = Kernel32.INSTANCE.OpenProcess(0x0400 | 0x0010, false, pid.getValue());
if (process == null)
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
// check ANSI function
final byte[] filePathAnsi = new byte[1025];
int length = Psapi.INSTANCE.GetModuleFileNameExA(process, null, filePathAnsi, filePathAnsi.length - 1);
if (length == 0)
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
assertTrue("Path didn't contain '" + searchSubStr + "': " + Native.toString(filePathAnsi), Native.toString(filePathAnsi).toLowerCase().contains(searchSubStr));
// check Unicode function
final char[] filePathUnicode = new char[1025];
length = Psapi.INSTANCE.GetModuleFileNameExW(process, null, filePathUnicode, filePathUnicode.length - 1);
if (length == 0)
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
assertTrue("Path didn't contain '" + searchSubStr + "': " + Native.toString(filePathUnicode), Native.toString(filePathUnicode).toLowerCase().contains(searchSubStr));
// check default function
final int memAllocSize = 1025 * Native.WCHAR_SIZE;
final Memory filePathDefault = new Memory(memAllocSize);
length = Psapi.INSTANCE.GetModuleFileNameEx(process, null, filePathDefault, (memAllocSize / Native.WCHAR_SIZE) - 1);
if (length == 0)
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
assertTrue("Path didn't contain '" + searchSubStr + "': " + Native.toString(filePathDefault.getCharArray(0, memAllocSize / Native.WCHAR_SIZE)), Native.toString(filePathDefault.getCharArray(0, memAllocSize / Native.WCHAR_SIZE)).toLowerCase().contains(searchSubStr));
} finally {
w.dispose();
}
}
use of com.sun.jna.platform.win32.WinDef.CHAR in project jna by java-native-access.
the class Excelautomation_KB_219151_Mod method displayQuaterlySales.
private static void displayQuaterlySales(ComIWorksheet sheet) {
// Determine how many quarters to display data for.
int iNumQtrs = 4;
for (; iNumQtrs >= 2; iNumQtrs--) {
JOptionPane pane = new JOptionPane(String.format("Enter sales data for %d quarter(s)?", iNumQtrs), JOptionPane.QUESTION_MESSAGE);
pane.setOptionType(JOptionPane.YES_NO_OPTION);
JDialog dialog = pane.createDialog("Input...");
dialog.setAlwaysOnTop(true);
dialog.show();
if (((Integer) pane.getValue()) == JOptionPane.YES_OPTION) {
break;
}
}
JOptionPane.showMessageDialog(null, String.format("Displaying data for %d quarter(s).", iNumQtrs));
// Starting at E1, fill headers for the number of columns selected.
ComIRange oResizeRange = sheet.getRange("E1", "E1").getResize(VARIANT_MISSING, iNumQtrs);
oResizeRange.setFormula("=\"Q\" & COLUMN() - 4 & CHAR(10) & \"Sales\"");
// Change the Orientation and WrapText properties for the headers.
oResizeRange.setOrientation(38);
oResizeRange.setWrapText(true);
// Fill the interior color of the headers.
oResizeRange.getInterior().setColorIndex(36);
// Fill the columns with a formula and apply a number format.
oResizeRange = sheet.getRange("E2", "E6").getResize(VARIANT_MISSING, iNumQtrs);
oResizeRange.setFormula("=RAND()*100");
oResizeRange.setNumberFormat("$0.00");
// Apply borders to the Sales data and headers.
oResizeRange = sheet.getRange("E1", "E6").getResize(VARIANT_MISSING, iNumQtrs);
oResizeRange.getBorders().setWeight(XlBorderWeight.xlThin);
// Add a Totals formula for the sales data and apply a border.
oResizeRange = sheet.getRange("E8", "E8").getResize(VARIANT_MISSING, iNumQtrs);
oResizeRange.setFormula("=SUM(E2:E6)");
Borders oResizeRangeBorders = oResizeRange.getBorders();
oResizeRangeBorders.setLineStyle(XlLineStyle.xlDouble);
oResizeRangeBorders.setWeight(XlBorderWeight.xlThick);
// Add a Chart for the selected data
oResizeRange = sheet.getRange("E2:E6").getResize(VARIANT_MISSING, iNumQtrs);
Chart chart = sheet.getParent().getCharts().Add(VARIANT_MISSING, VARIANT_MISSING, VARIANT_MISSING, VARIANT_MISSING);
// Java note: Assumption is, that VARIANT_MISSING is the correct indicator
// for missing values, it turns out, NULL is correct in this case...
chart.ChartWizard(oResizeRange, XlChartType.xl3DColumn, VARIANT_MISSING, XlRowCol.xlColumns, null, null, null, null, null, null, null);
chart.SeriesCollection(1).setXValues(sheet.getRange("C2", "C6"));
for (int i = 1; i <= iNumQtrs; i++) {
chart.SeriesCollection(i).setName("=\"Q" + Integer.toString(i) + "\"");
}
chart.Location(XlChartLocation.xlLocationAsObject, sheet.getName());
// Move the chart so as not to cover your data.
Shape shape = sheet.getShapes().Item(1);
shape.setTop(sheet.getRows(10).getTop());
shape.setLeft(sheet.getColumns(2).getLeft());
}
use of com.sun.jna.platform.win32.WinDef.CHAR in project jna by java-native-access.
the class Kernel32Test method testGetPrivateProfileSection.
public final void testGetPrivateProfileSection() throws IOException {
final File tmp = File.createTempFile("testGetPrivateProfileSection", ".ini");
tmp.deleteOnExit();
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
try {
writer.println("[X]");
writer.println("A=1");
writer.println("B=X");
} finally {
writer.close();
}
final char[] buffer = new char[9];
final DWORD len = Kernel32.INSTANCE.GetPrivateProfileSection("X", buffer, new DWORD(buffer.length), tmp.getCanonicalPath());
assertEquals(len.intValue(), 7);
assertEquals(new String(buffer), "A=1\0B=X\0\0");
}
use of com.sun.jna.platform.win32.WinDef.CHAR in project jna by java-native-access.
the class Kernel32VolumeManagementFunctionsTest method testEnumVolumes.
@Test
public void testEnumVolumes() {
char[] lpszVolumeName = new char[WinDef.MAX_PATH + 1];
HANDLE hFindVolume = assertValidHandle("FindFirstVolume", Kernel32.INSTANCE.FindFirstVolume(lpszVolumeName, lpszVolumeName.length));
try {
int foundPaths = 0;
do {
String volumeGUID = Native.toString(lpszVolumeName);
testEnumVolumeMountMoints(volumeGUID);
foundPaths += testGetVolumePathNamesForVolumeName(volumeGUID);
} while (Kernel32.INSTANCE.FindNextVolume(hFindVolume, lpszVolumeName, lpszVolumeName.length));
assertTrue("No paths were found", foundPaths > 0);
int hr = Kernel32.INSTANCE.GetLastError();
assertEquals("Bad volumes enum termination reason", WinError.ERROR_NO_MORE_FILES, hr);
} finally {
assertCallSucceeded("FindVolumeClose", Kernel32.INSTANCE.FindVolumeClose(hFindVolume));
}
}
use of com.sun.jna.platform.win32.WinDef.CHAR in project jna by java-native-access.
the class Kernel32Test method testGetPrivateProfileSectionNames.
public final void testGetPrivateProfileSectionNames() throws IOException {
final File tmp = File.createTempFile("testGetPrivateProfileSectionNames", ".ini");
tmp.deleteOnExit();
final PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmp)));
try {
writer.println("[S1]");
writer.println("[S2]");
} finally {
writer.close();
}
final char[] buffer = new char[7];
final DWORD len = Kernel32.INSTANCE.GetPrivateProfileSectionNames(buffer, new DWORD(buffer.length), tmp.getCanonicalPath());
assertEquals(len.intValue(), 5);
assertEquals(new String(buffer), "S1\0S2\0\0");
}
Aggregations