Search in sources :

Example 41 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class TypeInfoUtil method GetContainingTypeLib.

/**
     * Gets the containing type lib.
     * 
     * @return the containing type lib
     */
public ContainingTypeLib GetContainingTypeLib() {
    PointerByReference ppTLib = new PointerByReference();
    UINTByReference pIndex = new UINTByReference();
    HRESULT hr = this.typeInfo.GetContainingTypeLib(ppTLib, pIndex);
    COMUtils.checkRC(hr);
    return new ContainingTypeLib(new TypeLib(ppTLib.getValue()), pIndex.getValue().intValue());
}
Also used : UINTByReference(com.sun.jna.platform.win32.WinDef.UINTByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 42 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class TypeInfoUtil method getTypeComp.

/**
     * Gets the type comp.
     * 
     * @return the type comp
     */
public TypeComp getTypeComp() {
    PointerByReference ppTypeAttr = new PointerByReference();
    HRESULT hr = this.typeInfo.GetTypeComp(ppTypeAttr);
    COMUtils.checkRC(hr);
    return new TypeComp(ppTypeAttr.getValue());
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 43 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Crypt32Test method testCryptProtectUnprotectData.

public void testCryptProtectUnprotectData() {
    DATA_BLOB pDataIn = new DATA_BLOB("hello world");
    DATA_BLOB pDataEncrypted = new DATA_BLOB();
    try {
        assertTrue("CryptProtectData(Initial)", Crypt32.INSTANCE.CryptProtectData(pDataIn, "description", null, null, null, 0, pDataEncrypted));
        PointerByReference pDescription = new PointerByReference();
        try {
            DATA_BLOB pDataDecrypted = new DATA_BLOB();
            try {
                assertTrue("CryptProtectData(Crypt)", Crypt32.INSTANCE.CryptUnprotectData(pDataEncrypted, pDescription, null, null, null, 0, pDataDecrypted));
                assertEquals("description", pDescription.getValue().getWideString(0));
                assertEquals("hello world", pDataDecrypted.pbData.getString(0));
            } finally {
                Kernel32Util.freeLocalMemory(pDataDecrypted.pbData);
            }
        } finally {
            Kernel32Util.freeLocalMemory(pDescription.getValue());
        }
    } finally {
        Kernel32Util.freeLocalMemory(pDataEncrypted.pbData);
    }
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) DATA_BLOB(com.sun.jna.platform.win32.WinCrypt.DATA_BLOB)

Example 44 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class HybdridCOMInvocationTest method testOfficeInvocationDemonstration.

public void testOfficeInvocationDemonstration() {
    // THIS IS NOT A TEST
    //
    // This reproduces the problem by using the dispatch directly.
    PointerByReference pDispatch = new PointerByReference();
    HRESULT hr = Ole32.INSTANCE.CoCreateInstance(CLSID_WORD, null, WTypes.CLSCTX_SERVER, IID_APPLICATION, pDispatch);
    if (!COMUtils.SUCCEEDED(hr)) {
        LOG.log(Level.INFO, "HybdridCOMInvocationTest test was not run, MS Word object could not be instantiated.");
        return;
    }
    Dispatch dp = new Dispatch(pDispatch.getValue());
    // DispID of InchesToPoints
    DISPID dispId = new OaIdl.DISPID(0x00000172);
    // Interface _Application of MS Word type library
    WinDef.LCID LOCALE_SYSTEM_DEFAULT = Kernel32.INSTANCE.GetSystemDefaultLCID();
    Variant.VARIANT.ByReference result = new Variant.VARIANT.ByReference();
    OaIdl.EXCEPINFO.ByReference pExcepInfo = new OaIdl.EXCEPINFO.ByReference();
    IntByReference puArgErr = new IntByReference();
    WORD wFlagsMethod = new WinDef.WORD(OleAuto.DISPATCH_METHOD);
    WORD wFlagsGet = new WinDef.WORD(OleAuto.DISPATCH_PROPERTYGET);
    WORD wFlagsCombined = new WinDef.WORD(OleAuto.DISPATCH_METHOD | OleAuto.DISPATCH_PROPERTYGET);
    OleAuto.DISPPARAMS.ByReference pDispParams = new OleAuto.DISPPARAMS.ByReference();
    VARIANT[] params = new VARIANT[] { new VARIANT(1f) };
    pDispParams.setArgs(params);
    // Call InchesToPoints as a method
    hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsMethod, pDispParams, result, pExcepInfo, puArgErr);
    assertTrue(COMUtils.FAILED(hr));
    // Call InchesToPoints as a property getter
    hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsGet, pDispParams, result, pExcepInfo, puArgErr);
    assertTrue(COMUtils.FAILED(hr));
    // Call InchesToPoints as a hybrid
    hr = dp.Invoke(dispId, new REFIID(Guid.IID_NULL), LOCALE_SYSTEM_DEFAULT, wFlagsCombined, pDispParams, result, pExcepInfo, puArgErr);
    assertTrue(COMUtils.SUCCEEDED(hr));
    assertEquals(72.0f, result.floatValue());
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) WORD(com.sun.jna.platform.win32.WinDef.WORD) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) DISPID(com.sun.jna.platform.win32.OaIdl.DISPID) Dispatch(com.sun.jna.platform.win32.COM.Dispatch) REFIID(com.sun.jna.platform.win32.Guid.REFIID) PointerByReference(com.sun.jna.ptr.PointerByReference) IntByReference(com.sun.jna.ptr.IntByReference) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT) Variant(com.sun.jna.platform.win32.Variant) OleAuto(com.sun.jna.platform.win32.OleAuto) PointerByReference(com.sun.jna.ptr.PointerByReference) WinDef(com.sun.jna.platform.win32.WinDef) OaIdl(com.sun.jna.platform.win32.OaIdl)

Example 45 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jna by java-native-access.

the class Netapi32Test method testNetUserEnum.

public void testNetUserEnum() {
    PointerByReference bufptr = new PointerByReference();
    IntByReference entriesread = new IntByReference();
    IntByReference totalentries = new IntByReference();
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserEnum(null, 1, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries, null));
    USER_INFO_1 userinfo = new USER_INFO_1(bufptr.getValue());
    USER_INFO_1[] userinfos = (USER_INFO_1[]) userinfo.toArray(entriesread.getValue());
    for (USER_INFO_1 ui : userinfos) {
        assertTrue(ui.usri1_name.length() > 0);
    }
    assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) USER_INFO_1(com.sun.jna.platform.win32.LMAccess.USER_INFO_1)

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