Search in sources :

Example 61 with HRESULT

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;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Example 62 with HRESULT

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;
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) WinDef(com.sun.jna.platform.win32.WinDef)

Example 63 with HRESULT

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());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 64 with HRESULT

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());
}
Also used : ULONG(com.sun.jna.platform.win32.WinDef.ULONG) BOOLByReference(com.sun.jna.platform.win32.WinDef.BOOLByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) LPOLESTR(com.sun.jna.platform.win32.WTypes.LPOLESTR)

Example 65 with HRESULT

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;
}
Also used : ULONG(com.sun.jna.platform.win32.WinDef.ULONG) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) LPOLESTR(com.sun.jna.platform.win32.WTypes.LPOLESTR) MEMBERID(com.sun.jna.platform.win32.OaIdl.MEMBERID) LPOLESTR(com.sun.jna.platform.win32.WTypes.LPOLESTR) USHORTByReference(com.sun.jna.platform.win32.WinDef.USHORTByReference) Pointer(com.sun.jna.Pointer) WTypes(com.sun.jna.platform.win32.WTypes)

Aggregations

HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)102 PointerByReference (com.sun.jna.ptr.PointerByReference)57 Test (org.junit.Test)26 REFIID (com.sun.jna.platform.win32.Guid.REFIID)20 UINT (com.sun.jna.platform.win32.WinDef.UINT)15 WString (com.sun.jna.WString)12 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)12 WinNT (com.sun.jna.platform.win32.WinNT)12 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)11 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)10 MEMBERID (com.sun.jna.platform.win32.OaIdl.MEMBERID)9 BSTRByReference (com.sun.jna.platform.win32.WTypes.BSTRByReference)9 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)9 IID (com.sun.jna.platform.win32.Guid.IID)8 DISPIDByReference (com.sun.jna.platform.win32.OaIdl.DISPIDByReference)8 IntByReference (com.sun.jna.ptr.IntByReference)8 UINTByReference (com.sun.jna.platform.win32.WinDef.UINTByReference)7 COMException (com.sun.jna.platform.win32.COM.COMException)6 ConnectionPoint (com.sun.jna.platform.win32.COM.ConnectionPoint)6 Pointer (com.sun.jna.Pointer)5