use of com.sun.jna.platform.win32.WinNT.HRESULT 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.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class ObjectFactory method getRunningObjectTable.
/**
* CoInitialize must be called be fore this method. Either explicitly or
* implicitly via other methods.
*
* @return running object table
*/
public IRunningObjectTable getRunningObjectTable() {
assert COMUtils.comIsInitialized() : "COM not initialized";
final PointerByReference rotPtr = new PointerByReference();
HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new WinDef.DWORD(0), rotPtr);
COMUtils.checkRC(hr);
com.sun.jna.platform.win32.COM.RunningObjectTable raw = new com.sun.jna.platform.win32.COM.RunningObjectTable(rotPtr.getValue());
IRunningObjectTable rot = new RunningObjectTable(raw, this);
return rot;
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class TypeLibUtil method GetTypeComp.
/**
* Gets the type comp.
*
* @return the i type comp. by reference
*/
public TypeComp GetTypeComp() {
PointerByReference ppTComp = new PointerByReference();
HRESULT hr = this.typelib.GetTypeComp(ppTComp);
COMUtils.checkRC(hr);
return new TypeComp(ppTComp.getValue());
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class TypeLibUtil method IsName.
/**
* Checks if is name.
*
* @param nameBuf
* the name buf
* @param hashVal
* the hash val
* @return the checks if is name
*/
public IsName IsName(String nameBuf, int hashVal) {
LPOLESTR szNameBuf = new LPOLESTR(nameBuf);
ULONG lHashVal = new ULONG(hashVal);
BOOLByReference pfName = new BOOLByReference();
HRESULT hr = this.typelib.IsName(szNameBuf, lHashVal, pfName);
COMUtils.checkRC(hr);
return new IsName(szNameBuf.getValue(), pfName.getValue().booleanValue());
}
use of com.sun.jna.platform.win32.WinNT.HRESULT in project jna by java-native-access.
the class TypeLibUtil method FindName.
/**
* Find name.
*
* @param name
* the name
* @param hashVal
* the hash val or 0 if unknown
* @param maxResult
* maximum number of items to search
* @return the find name
*/
public FindName FindName(String name, int hashVal, short maxResult) {
Pointer p = Ole32.INSTANCE.CoTaskMemAlloc((name.length() + 1L) * Native.WCHAR_SIZE);
WTypes.LPOLESTR olestr = new WTypes.LPOLESTR(p);
olestr.setValue(name);
ULONG lHashVal = new ULONG(hashVal);
USHORTByReference pcFound = new USHORTByReference(maxResult);
Pointer[] ppTInfo = new Pointer[maxResult];
MEMBERID[] rgMemId = new MEMBERID[maxResult];
HRESULT hr = this.typelib.FindName(olestr, lHashVal, ppTInfo, rgMemId, pcFound);
COMUtils.checkRC(hr);
FindName findName = new FindName(olestr.getValue(), ppTInfo, rgMemId, pcFound.getValue().shortValue());
Ole32.INSTANCE.CoTaskMemFree(p);
return findName;
}
Aggregations