use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class Shell32Util method getKnownFolderPath.
/**
* Retrieves the full path of a known folder identified by the folder's KNOWNFOLDERID. This function replaces
* {@link #getFolderPath}. That older function is now simply a wrapper for getKnownFolderPath
* @param guid the KNOWNFOLDERS GUID as defined in {@link KnownFolders}
* @return the path of the known folder. The returned path does not include a trailing backslash. For example,
* "C:\Users" is returned rather than "C:\Users\".
* @throws Win32Exception if the guid references a KNOWNFOLDERID which does not have a path (such as a folder marked
* as KF_CATEGORY_VIRTUAL) or that the KNOWNFOLDERID is not present on the system. Not all KNOWNFOLDERID values are
* present on all systems.
*/
public static String getKnownFolderPath(GUID guid) throws Win32Exception {
int flags = ShlObj.KNOWN_FOLDER_FLAG.NONE.getFlag();
PointerByReference outPath = new PointerByReference();
HANDLE token = null;
HRESULT hr = Shell32.INSTANCE.SHGetKnownFolderPath(guid, flags, token, outPath);
if (!W32Errors.SUCCEEDED(hr.intValue())) {
throw new Win32Exception(hr);
}
String result = outPath.getValue().getWideString(0);
Ole32.INSTANCE.CoTaskMemFree(outPath.getValue());
return result;
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class VersionUtil method getFileVersionInfo.
/**
* Gets the file's version number info
*
* @param filePath
* The path to the file
* @return The VS_FIXEDFILEINFO structure read from the file.<br>
* Use the getFileVersionMajor(), getFileVersionMinor(),
* getFileVersionRevision(), and getFileVersionBuild()
* @throws UnsupportedOperationException
* if VerQueryValue fails to get version info from the file.
*/
public static VS_FIXEDFILEINFO getFileVersionInfo(String filePath) {
IntByReference dwDummy = new IntByReference();
int versionLength = Version.INSTANCE.GetFileVersionInfoSize(filePath, dwDummy);
// throw a Win32Exception with GetLastError()
if (versionLength == 0) {
throw new Win32Exception(Native.getLastError());
}
// buffer to hold version info
Pointer lpData = new Memory(versionLength);
// pointer to pointer to location in aforementioned buffer
PointerByReference lplpBuffer = new PointerByReference();
if (!Version.INSTANCE.GetFileVersionInfo(filePath, 0, versionLength, lpData)) {
throw new Win32Exception(Native.getLastError());
}
// here to make VerQueryValue happy.
IntByReference puLen = new IntByReference();
// this does not set GetLastError, so no need to throw a Win32Exception
if (!Version.INSTANCE.VerQueryValue(lpData, "\\", lplpBuffer, puLen)) {
throw new UnsupportedOperationException("Unable to extract version info from the file: \"" + filePath + "\"");
}
VS_FIXEDFILEINFO fileInfo = new VS_FIXEDFILEINFO(lplpBuffer.getValue());
fileInfo.read();
return fileInfo;
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class W32FileMonitor method waitForChange.
private FileInfo waitForChange() {
IntByReference rcount = new IntByReference();
ULONG_PTRByReference rkey = new ULONG_PTRByReference();
PointerByReference roverlap = new PointerByReference();
if (!Kernel32.INSTANCE.GetQueuedCompletionStatus(port, rcount, rkey, roverlap, WinBase.INFINITE)) {
return null;
}
synchronized (this) {
return handleMap.get(new HANDLE(rkey.getValue().toPointer()));
}
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class EnumMoniker method cacheNext.
protected void cacheNext() {
assert COMUtils.comIsInitialized() : "COM not initialized";
final PointerByReference rgelt = new PointerByReference();
final WinDef.ULONGByReference pceltFetched = new WinDef.ULONGByReference();
WinNT.HRESULT hr = this.raw.Next(new WinDef.ULONG(1), rgelt, pceltFetched);
if (WinNT.S_OK.equals(hr) && pceltFetched.getValue().intValue() > 0) {
this.rawNext = new Moniker(rgelt.getValue());
} else {
if (!WinNT.S_FALSE.equals(hr)) {
COMUtils.checkRC(hr);
}
this.rawNext = null;
}
}
use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.
the class ObjectFactory method createObject.
/**
* Creates a new COM object (CoCreateInstance) for the given progId and
* returns a ProxyObject for the given interface.
*/
public <T> T createObject(Class<T> comInterface) {
assert COMUtils.comIsInitialized() : "COM not initialized";
ComObject comObectAnnotation = comInterface.getAnnotation(ComObject.class);
if (null == comObectAnnotation) {
throw new COMException("createObject: Interface must define a value for either clsId or progId via the ComInterface annotation");
}
final GUID guid = this.discoverClsId(comObectAnnotation);
final PointerByReference ptrDisp = new PointerByReference();
WinNT.HRESULT hr = Ole32.INSTANCE.CoCreateInstance(guid, null, WTypes.CLSCTX_SERVER, IDispatch.IID_IDISPATCH, ptrDisp);
COMUtils.checkRC(hr);
Dispatch d = new Dispatch(ptrDisp.getValue());
T t = this.createProxy(comInterface, d);
//CoCreateInstance returns a pointer to COM object with a +1 reference count, so we must drop one
//Note: the createProxy adds one
int n = d.Release();
return t;
}
Aggregations