Search in sources :

Example 81 with PointerByReference

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;
}
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 82 with PointerByReference

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;
}
Also used : VS_FIXEDFILEINFO(com.sun.jna.platform.win32.VerRsrc.VS_FIXEDFILEINFO) IntByReference(com.sun.jna.ptr.IntByReference) Memory(com.sun.jna.Memory) PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer) Win32Exception(com.sun.jna.platform.win32.Win32Exception)

Example 83 with PointerByReference

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

Example 84 with PointerByReference

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

Example 85 with PointerByReference

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;
}
Also used : COMException(com.sun.jna.platform.win32.COM.COMException) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) WinNT(com.sun.jna.platform.win32.WinNT) PointerByReference(com.sun.jna.ptr.PointerByReference) ComObject(com.sun.jna.platform.win32.COM.util.annotation.ComObject) GUID(com.sun.jna.platform.win32.Guid.GUID) WinNT(com.sun.jna.platform.win32.WinNT) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) IDispatch(com.sun.jna.platform.win32.COM.IDispatch) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT)

Aggregations

PointerByReference (com.sun.jna.ptr.PointerByReference)128 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)54 IntByReference (com.sun.jna.ptr.IntByReference)35 Pointer (com.sun.jna.Pointer)20 Test (org.junit.Test)19 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)18 REFIID (com.sun.jna.platform.win32.Guid.REFIID)13 File (java.io.File)13 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)10 PSID (com.sun.jna.platform.win32.WinNT.PSID)10 Memory (com.sun.jna.Memory)8 WString (com.sun.jna.WString)8 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)7 ULONGByReference (com.sun.jna.platform.win32.WinDef.ULONGByReference)7 WinNT (com.sun.jna.platform.win32.WinNT)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 IID (com.sun.jna.platform.win32.Guid.IID)6 ArrayList (java.util.ArrayList)6 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)5 UINT (com.sun.jna.platform.win32.WinDef.UINT)5