Search in sources :

Example 1 with HCONV

use of com.sun.jna.platform.win32.Ddeml.HCONV 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 HCONV

use of com.sun.jna.platform.win32.Ddeml.HCONV 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 HCONV

use of com.sun.jna.platform.win32.Ddeml.HCONV 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 HCONV

use of com.sun.jna.platform.win32.Ddeml.HCONV in project jna by java-native-access.

the class DdemlUtilTest method testExecute.

@Test
public void testExecute() throws InterruptedException {
    final String serviceName = "TestService";
    final String topicName = "TestTopic";
    final String testExecute = "Execute�������";
    final CountDownLatch executeReceived = new CountDownLatch(1);
    StandaloneDdeClient client = null;
    StandaloneDdeClient server = null;
    try {
        client = new StandaloneDdeClient() {

            {
                this.initialize(Ddeml.APPCMD_CLIENTONLY | Ddeml.CBF_SKIP_REGISTRATIONS | Ddeml.CBF_SKIP_UNREGISTRATIONS);
            }
        };
        server = new StandaloneDdeClient() {

            private final ConnectHandler connectHandler = new ConnectHandler() {

                public boolean onConnect(int transactionType, HSZ topic, HSZ service, Ddeml.CONVCONTEXT convcontext, boolean sameInstance) {
                    return topicName.equals(queryString(topic));
                }
            };

            private final ExecuteHandler executeHandler = new ExecuteHandler() {

                public int onExecute(int transactionType, HCONV hconv, HSZ topic, Ddeml.HDDEDATA commandStringData) {
                    Pointer[] pointer = new Pointer[] { accessData(commandStringData, null) };
                    try {
                        String commandString = pointer[0].getWideString(0);
                        if (testExecute.equals(commandString) && queryString(topic).equals(topicName)) {
                            executeReceived.countDown();
                            return Ddeml.DDE_FACK;
                        }
                    } finally {
                        synchronized (pointer) {
                            unaccessData(commandStringData);
                        }
                    }
                    return Ddeml.DDE_FNOTPROCESSED;
                }
            };

            {
                registerConnectHandler(connectHandler);
                registerExecuteHandler(executeHandler);
                this.initialize(Ddeml.APPCMD_FILTERINITS | Ddeml.CBF_SKIP_ALLNOTIFICATIONS);
            }
        };
        server.nameService(serviceName, Ddeml.DNS_REGISTER);
        IDdeConnection con = client.connect(serviceName, topicName, null);
        con.execute(testExecute, 5 * 1000, null, null);
        assertTrue(executeReceived.await(5, TimeUnit.SECONDS));
    } finally {
        closeQuitely(client);
        closeQuitely(server);
    }
}
Also used : ConnectHandler(com.sun.jna.platform.win32.DdemlUtil.ConnectHandler) ExecuteHandler(com.sun.jna.platform.win32.DdemlUtil.ExecuteHandler) HDDEDATA(com.sun.jna.platform.win32.Ddeml.HDDEDATA) StandaloneDdeClient(com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient) HCONV(com.sun.jna.platform.win32.Ddeml.HCONV) Pointer(com.sun.jna.Pointer) IDdeConnection(com.sun.jna.platform.win32.DdemlUtil.IDdeConnection) CountDownLatch(java.util.concurrent.CountDownLatch) HSZ(com.sun.jna.platform.win32.Ddeml.HSZ) Test(org.junit.Test)

Example 5 with HCONV

use of com.sun.jna.platform.win32.Ddeml.HCONV in project jna by java-native-access.

the class DdemlUtilTest method testConnectDisconnect.

@Test
public void testConnectDisconnect() throws InterruptedException {
    final String serviceName = "TestService";
    final String topicName = "TestTopic";
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final CountDownLatch disconnectLatch = new CountDownLatch(1);
    StandaloneDdeClient client = null;
    StandaloneDdeClient server = null;
    try {
        client = new StandaloneDdeClient() {

            {
                this.initialize(Ddeml.APPCMD_CLIENTONLY | Ddeml.CBF_SKIP_REGISTRATIONS | Ddeml.CBF_SKIP_UNREGISTRATIONS);
            }
        };
        server = new StandaloneDdeClient() {

            private final ConnectHandler connectHandler = new ConnectHandler() {

                public boolean onConnect(int transactionType, HSZ topic, HSZ service, Ddeml.CONVCONTEXT convcontext, boolean sameInstance) {
                    return topicName.equals(queryString(topic));
                }
            };

            private final ConnectConfirmHandler connectConfirmHandler = new ConnectConfirmHandler() {

                public void onConnectConfirm(int transactionType, HCONV hconv, HSZ topic, HSZ service, boolean sameInstance) {
                    if (topicName.equals(queryString(topic))) {
                        connectLatch.countDown();
                    }
                }
            };

            private final DisconnectHandler disconnectHandler = new DisconnectHandler() {

                public void onDisconnect(int transactionType, HCONV hconv, boolean sameInstance) {
                    disconnectLatch.countDown();
                }
            };

            {
                registerConnectHandler(connectHandler);
                registerConnectConfirmHandler(connectConfirmHandler);
                registerDisconnectHandler(disconnectHandler);
                this.initialize(Ddeml.APPCMD_FILTERINITS | Ddeml.CBF_SKIP_REGISTRATIONS | Ddeml.CBF_SKIP_UNREGISTRATIONS);
            }
        };
        server.nameService(serviceName, Ddeml.DNS_REGISTER);
        IDdeConnection connection = client.connect(serviceName, topicName, null);
        assertTrue("Failed to connect", connectLatch.await(5, TimeUnit.SECONDS));
        connection.close();
        assertTrue("Failed to disconnect", disconnectLatch.await(5, TimeUnit.SECONDS));
    } finally {
        closeQuitely(client);
        closeQuitely(server);
    }
}
Also used : DisconnectHandler(com.sun.jna.platform.win32.DdemlUtil.DisconnectHandler) ConnectHandler(com.sun.jna.platform.win32.DdemlUtil.ConnectHandler) StandaloneDdeClient(com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient) HCONV(com.sun.jna.platform.win32.Ddeml.HCONV) ConnectConfirmHandler(com.sun.jna.platform.win32.DdemlUtil.ConnectConfirmHandler) IDdeConnection(com.sun.jna.platform.win32.DdemlUtil.IDdeConnection) CountDownLatch(java.util.concurrent.CountDownLatch) HSZ(com.sun.jna.platform.win32.Ddeml.HSZ) Test(org.junit.Test)

Aggregations

HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)12 Test (org.junit.Test)12 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)10 HCONV (com.sun.jna.platform.win32.Ddeml.HCONV)9 ConnectHandler (com.sun.jna.platform.win32.DdemlUtil.ConnectHandler)9 IDdeConnection (com.sun.jna.platform.win32.DdemlUtil.IDdeConnection)9 StandaloneDdeClient (com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 Pointer (com.sun.jna.Pointer)8 Memory (com.sun.jna.Memory)5 ExecuteHandler (com.sun.jna.platform.win32.DdemlUtil.ExecuteHandler)4 ULONG_PTR (com.sun.jna.platform.win32.BaseTSD.ULONG_PTR)3 DdeCallback (com.sun.jna.platform.win32.Ddeml.DdeCallback)3 XactCompleteHandler (com.sun.jna.platform.win32.DdemlUtil.XactCompleteHandler)3 DWORDByReference (com.sun.jna.platform.win32.WinDef.DWORDByReference)3 PVOID (com.sun.jna.platform.win32.WinDef.PVOID)3 ConnectConfirmHandler (com.sun.jna.platform.win32.DdemlUtil.ConnectConfirmHandler)2 DisconnectHandler (com.sun.jna.platform.win32.DdemlUtil.DisconnectHandler)2 CONVINFO (com.sun.jna.platform.win32.Ddeml.CONVINFO)1 AdvdataHandler (com.sun.jna.platform.win32.DdemlUtil.AdvdataHandler)1