Search in sources :

Example 1 with PVOID

use of com.sun.jna.platform.win32.WinDef.PVOID in project jna by java-native-access.

the class DdemlTest method testInitialization.

@Test
public void testInitialization() {
    DdeCallback callback = new Ddeml.DdeCallback() {

        public WinDef.PVOID ddeCallback(int wType, int wFmt, Ddeml.HCONV hConv, Ddeml.HSZ hsz1, Ddeml.HSZ hsz2, Ddeml.HDDEDATA hData, BaseTSD.ULONG_PTR lData1, BaseTSD.ULONG_PTR lData2) {
            return new PVOID();
        }
    };
    DWORDByReference pidInst = new DWORDByReference();
    int initResult = Ddeml.INSTANCE.DdeInitialize(pidInst, callback, Ddeml.APPCMD_CLIENTONLY, 0);
    assertEquals(Ddeml.DMLERR_NO_ERROR, initResult);
    boolean uninitResult = Ddeml.INSTANCE.DdeUninitialize(pidInst.getValue().intValue());
    assertTrue(uninitResult);
}
Also used : HDDEDATA(com.sun.jna.platform.win32.Ddeml.HDDEDATA) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) PVOID(com.sun.jna.platform.win32.WinDef.PVOID) HSZ(com.sun.jna.platform.win32.Ddeml.HSZ) DdeCallback(com.sun.jna.platform.win32.Ddeml.DdeCallback) Test(org.junit.Test)

Example 2 with PVOID

use of com.sun.jna.platform.win32.WinDef.PVOID in project jna by java-native-access.

the class DdemlTest method testStringHandling.

@Test
public void testStringHandling() {
    DdeCallback callback = new Ddeml.DdeCallback() {

        public WinDef.PVOID ddeCallback(int wType, int wFmt, Ddeml.HCONV hConv, Ddeml.HSZ hsz1, Ddeml.HSZ hsz2, Ddeml.HDDEDATA hData, BaseTSD.ULONG_PTR lData1, BaseTSD.ULONG_PTR lData2) {
            return new PVOID();
        }
    };
    DWORDByReference pidInst = new DWORDByReference();
    int initResult = Ddeml.INSTANCE.DdeInitialize(pidInst, callback, Ddeml.APPCMD_CLIENTONLY, 0);
    assertEquals(Ddeml.DMLERR_NO_ERROR, initResult);
    HSZ handle = Ddeml.INSTANCE.DdeCreateStringHandle(pidInst.getValue().intValue(), "Test", Ddeml.CP_WINUNICODE);
    assertNotNull(handle);
    // String in DDE can not exceed 255 Chars
    Memory mem = new Memory(256 * 2);
    Ddeml.INSTANCE.DdeQueryString(pidInst.getValue().intValue(), handle, mem, 256, Ddeml.CP_WINUNICODE);
    assertEquals("Test", mem.getWideString(0));
    synchronized (mem) {
    }
    assertTrue(Ddeml.INSTANCE.DdeFreeStringHandle(pidInst.getValue().intValue(), handle));
    // Test overlong creation -- according to documentation this must fail
    StringBuilder testString = new StringBuilder();
    for (int i = 0; i < 30; i++) {
        testString.append("0123456789");
    }
    HSZ handle2 = Ddeml.INSTANCE.DdeCreateStringHandle(pidInst.getValue().intValue(), testString.toString(), Ddeml.CP_WINUNICODE);
    assertNull(handle2);
    boolean uninitResult = Ddeml.INSTANCE.DdeUninitialize(pidInst.getValue().intValue());
    assertTrue(uninitResult);
}
Also used : HDDEDATA(com.sun.jna.platform.win32.Ddeml.HDDEDATA) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) Memory(com.sun.jna.Memory) PVOID(com.sun.jna.platform.win32.WinDef.PVOID) HSZ(com.sun.jna.platform.win32.Ddeml.HSZ) DdeCallback(com.sun.jna.platform.win32.Ddeml.DdeCallback) Test(org.junit.Test)

Example 3 with PVOID

use of com.sun.jna.platform.win32.WinDef.PVOID in project jna by java-native-access.

the class DdemlTest method testMemoryHandling.

@Test
public void testMemoryHandling() {
    DdeCallback callback = new Ddeml.DdeCallback() {

        public WinDef.PVOID ddeCallback(int wType, int wFmt, Ddeml.HCONV hConv, Ddeml.HSZ hsz1, Ddeml.HSZ hsz2, Ddeml.HDDEDATA hData, BaseTSD.ULONG_PTR lData1, BaseTSD.ULONG_PTR lData2) {
            return new PVOID();
        }
    };
    DWORDByReference pidInst = new DWORDByReference();
    int initResult = Ddeml.INSTANCE.DdeInitialize(pidInst, callback, Ddeml.APPCMD_CLIENTONLY, 0);
    assertEquals(Ddeml.DMLERR_NO_ERROR, initResult);
    // Acquire dummy handle
    HSZ hsz = Ddeml.INSTANCE.DdeCreateStringHandle(pidInst.getValue().intValue(), "Dummy", Ddeml.CP_WINUNICODE);
    String testStringPart1 = "Hallo ";
    String testStringPart2 = "Welt";
    // Create Handle
    // String in DDE can not exceed 255 Chars
    Memory mem = new Memory(256 * 2);
    mem.setWideString(0, testStringPart1);
    HDDEDATA data = Ddeml.INSTANCE.DdeCreateDataHandle(pidInst.getValue().intValue(), mem, testStringPart1.length() * 2, 0, hsz, WinUser.CF_UNICODETEXT, Ddeml.HDATA_APPOWNED);
    mem.setWideString(0, testStringPart2);
    Ddeml.INSTANCE.DdeAddData(data, mem, (testStringPart2.length() + 1) * 2, testStringPart1.length() * 2);
    DWORDByReference dataSize = new DWORDByReference();
    Pointer resultPointer = Ddeml.INSTANCE.DdeAccessData(data, dataSize);
    assertEquals((testStringPart1.length() + testStringPart2.length() + 1) * 2, dataSize.getValue().intValue());
    assertEquals(testStringPart1 + testStringPart2, resultPointer.getWideString(0));
    boolean result = Ddeml.INSTANCE.DdeUnaccessData(data);
    int readSize = Ddeml.INSTANCE.DdeGetData(data, mem, (int) mem.size(), 0);
    assertEquals((testStringPart1.length() + testStringPart2.length() + 1) * 2, readSize);
    assertEquals(testStringPart1 + testStringPart2, mem.getWideString(0));
    assertTrue(result);
    result = Ddeml.INSTANCE.DdeFreeDataHandle(data);
    assertTrue(result);
    synchronized (mem) {
    }
    result = Ddeml.INSTANCE.DdeUninitialize(pidInst.getValue().intValue());
    assertTrue(result);
}
Also used : DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) Memory(com.sun.jna.Memory) Pointer(com.sun.jna.Pointer) PVOID(com.sun.jna.platform.win32.WinDef.PVOID) HSZ(com.sun.jna.platform.win32.Ddeml.HSZ) DdeCallback(com.sun.jna.platform.win32.Ddeml.DdeCallback) HDDEDATA(com.sun.jna.platform.win32.Ddeml.HDDEDATA) Test(org.junit.Test)

Example 4 with PVOID

use of com.sun.jna.platform.win32.WinDef.PVOID in project jna by java-native-access.

the class TypeInfoUtil method Invoke.

/**
     * Invoke.
     * 
     * @param pvInstance
     *            the pv instance
     * @param memid
     *            the memid
     * @param wFlags
     *            the w flags
     * @param pDispParams
     *            the disp params
     * @return the invoke
     */
public Invoke Invoke(PVOID pvInstance, MEMBERID memid, WORD wFlags, DISPPARAMS.ByReference pDispParams) {
    VARIANT.ByReference pVarResult = new VARIANT.ByReference();
    EXCEPINFO.ByReference pExcepInfo = new EXCEPINFO.ByReference();
    UINTByReference puArgErr = new UINTByReference();
    HRESULT hr = this.typeInfo.Invoke(pvInstance, memid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    COMUtils.checkRC(hr);
    return new Invoke(pVarResult, pExcepInfo, puArgErr.getValue().intValue());
}
Also used : UINTByReference(com.sun.jna.platform.win32.WinDef.UINTByReference) HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) EXCEPINFO(com.sun.jna.platform.win32.OaIdl.EXCEPINFO) HREFTYPEByReference(com.sun.jna.platform.win32.OaIdl.HREFTYPEByReference) UINTByReference(com.sun.jna.platform.win32.WinDef.UINTByReference) DWORDByReference(com.sun.jna.platform.win32.WinDef.DWORDByReference) BSTRByReference(com.sun.jna.platform.win32.WTypes.BSTRByReference) PointerByReference(com.sun.jna.ptr.PointerByReference) WORDByReference(com.sun.jna.platform.win32.WinDef.WORDByReference) IntByReference(com.sun.jna.ptr.IntByReference) VARIANT(com.sun.jna.platform.win32.Variant.VARIANT)

Aggregations

DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)4 DdeCallback (com.sun.jna.platform.win32.Ddeml.DdeCallback)3 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)3 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)3 PVOID (com.sun.jna.platform.win32.WinDef.PVOID)3 Test (org.junit.Test)3 Memory (com.sun.jna.Memory)2 Pointer (com.sun.jna.Pointer)1 EXCEPINFO (com.sun.jna.platform.win32.OaIdl.EXCEPINFO)1 HREFTYPEByReference (com.sun.jna.platform.win32.OaIdl.HREFTYPEByReference)1 VARIANT (com.sun.jna.platform.win32.Variant.VARIANT)1 BSTRByReference (com.sun.jna.platform.win32.WTypes.BSTRByReference)1 UINTByReference (com.sun.jna.platform.win32.WinDef.UINTByReference)1 WORDByReference (com.sun.jna.platform.win32.WinDef.WORDByReference)1 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)1 IntByReference (com.sun.jna.ptr.IntByReference)1 PointerByReference (com.sun.jna.ptr.PointerByReference)1