Search in sources :

Example 1 with CONVINFO

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

the class DdemlUtilTest method testQueryConvInfoSetUserHandle.

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

            private final XactCompleteHandler xactCompleteHandler = new XactCompleteHandler() {

                public void onXactComplete(int transactionType, int dataFormat, HCONV hConv, HSZ topic, HSZ item, HDDEDATA hdata, ULONG_PTR transactionIdentifier, ULONG_PTR statusFlag) {
                    CONVINFO convInfo = wrap(hConv).queryConvInfo(transactionIdentifier.intValue());
                    if (convInfo.hUser.intValue() == 42) {
                        executesProcessed.countDown();
                    }
                }
            };

            {
                registerXactCompleteHandler(xactCompleteHandler);
                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)) {
                            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, Ddeml.TIMEOUT_ASYNC, null, new BaseTSD.DWORD_PTR(42L));
        assertTrue(executesProcessed.await(3, TimeUnit.SECONDS));
    } finally {
        closeQuitely(client);
        closeQuitely(server);
    }
}
Also used : HCONV(com.sun.jna.platform.win32.Ddeml.HCONV) Pointer(com.sun.jna.Pointer) CountDownLatch(java.util.concurrent.CountDownLatch) ULONG_PTR(com.sun.jna.platform.win32.BaseTSD.ULONG_PTR) HSZ(com.sun.jna.platform.win32.Ddeml.HSZ) CONVINFO(com.sun.jna.platform.win32.Ddeml.CONVINFO) 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) XactCompleteHandler(com.sun.jna.platform.win32.DdemlUtil.XactCompleteHandler) IDdeConnection(com.sun.jna.platform.win32.DdemlUtil.IDdeConnection) Test(org.junit.Test)

Aggregations

Pointer (com.sun.jna.Pointer)1 ULONG_PTR (com.sun.jna.platform.win32.BaseTSD.ULONG_PTR)1 CONVINFO (com.sun.jna.platform.win32.Ddeml.CONVINFO)1 HCONV (com.sun.jna.platform.win32.Ddeml.HCONV)1 HDDEDATA (com.sun.jna.platform.win32.Ddeml.HDDEDATA)1 HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)1 ConnectHandler (com.sun.jna.platform.win32.DdemlUtil.ConnectHandler)1 ExecuteHandler (com.sun.jna.platform.win32.DdemlUtil.ExecuteHandler)1 IDdeConnection (com.sun.jna.platform.win32.DdemlUtil.IDdeConnection)1 StandaloneDdeClient (com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient)1 XactCompleteHandler (com.sun.jna.platform.win32.DdemlUtil.XactCompleteHandler)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1