Exemplo n.º 1
0
        public void TryConnect(string service, string topic, IDDEConversationListener listener)
        {
            var op = this.dispatcher.BeginInvoke(new Action(delegate()
            {
                if (idInst == 0)
                {
                    listener.OnConnect(null);
                }

                using (var hszService = new DdeStringHandle(idInst, service))
                    using (var hszTopic = new DdeStringHandle(idInst, topic))
                    {
                        var hConv = DDEML.DdeConnect(idInst, hszService.Handle, hszTopic.Handle, IntPtr.Zero);
                        if (hConv == IntPtr.Zero)
                        {
                            var errno = DDEML.DdeGetLastError(idInst);
                            var error = DDEML.GetErrorString(errno) + " (" + errno.ToString() + ")";
                            Log.Emit("dde-connect-failed", "service", service, "topic", topic, "error", error);
                            listener.OnConnect(null);
                        }
                        else
                        {
                            Log.Emit("dde-connect", "service", service, "topic", topic, "hConv", hConv);
                            var conv = new Conversation(this, service, topic, hConv, listener);
                            this.conversations.Add(hConv, conv);
                            listener.OnConnect(conv);
                        }
                    }
            }));
        }
Exemplo n.º 2
0
            void Transact(string itemName, int wFmt, int wType, DDETransactionCallback callback)
            {
                Client.dispatcher.BeginInvoke(new Action(delegate()
                {
                    if (Handle == IntPtr.Zero)
                    {
                        return;
                    }

                    int res = 0;
                    using (var hsz = new DdeStringHandle(Client.idInst, itemName))
                    {
                        using (var hData = new DdeDataHandle(DDEML.DdeClientTransaction(null, 0, Handle, hsz.Handle, wFmt, wType, DDEML.TIMEOUT_ASYNC, ref res)))
                        {
                            Log.Emit("dde-transact", "hConv", this.Handle, "item", itemName, "wFmt", wFmt, "wType", DDEML.GetTypeString(wType), "callback", callback != null, "id", res);
                            if (hData.Handle == IntPtr.Zero)
                            {
                                var errno = DDEML.DdeGetLastError(Client.idInst);
                                Log.Emit("dde-transact-failed", "error", DDEML.GetErrorString(errno) + " (" + errno.ToString() + ")");
                                if (callback != null)
                                {
                                    callback(itemName, false, null);
                                }
                                this.Disconnect();
                            }
                            else
                            {
                                if (callback != null)
                                {
                                    if (res == 0)
                                    {
                                        callback(itemName, false, null);
                                    }
                                    else if (callback != null & res != 0)
                                    {
                                        var id = new IntPtr(res);
                                        transactions.Add(id, new Transaction(id, callback));
                                    }
                                }
                            }
                        }
                    }
                }));
            }
Exemplo n.º 3
0
        public void TryConnect(string service, string topic, IDDEConversationListener listener)
        {
            var op = this.dispatcher.BeginInvoke(new Action(delegate()
            {
                if(idInst == 0)
                    listener.OnConnect(null);

                using(var hszService = new DdeStringHandle(idInst, service))
                using(var hszTopic = new DdeStringHandle(idInst, topic))
                {
                    var hConv = DDEML.DdeConnect(idInst, hszService.Handle, hszTopic.Handle, IntPtr.Zero);
                    if(hConv == IntPtr.Zero)
                    {
                        var errno = DDEML.DdeGetLastError(idInst);
                        var error = DDEML.GetErrorString(errno) + " (" + errno.ToString() + ")";
                        Log.Emit("dde-connect-failed", "service", service, "topic", topic, "error", error);
                        listener.OnConnect(null);
                    }
                    else
                    {
                        Log.Emit("dde-connect", "service", service, "topic", topic, "hConv", hConv);
                        var conv = new Conversation(this, service, topic, hConv, listener);
                        this.conversations.Add(hConv, conv);
                        listener.OnConnect(conv);
                    }
                }
            }));
        }
Exemplo n.º 4
0
            void Transact(string itemName, int wFmt, int wType, DDETransactionCallback callback)
            {
                Client.dispatcher.BeginInvoke(new Action(delegate()
                {
                    if(Handle == IntPtr.Zero)
                        return;

                    int res = 0;
                    using(var hsz = new DdeStringHandle(Client.idInst, itemName))
                    {
                        using(var hData = new DdeDataHandle(DDEML.DdeClientTransaction(null, 0, Handle, hsz.Handle, wFmt, wType, DDEML.TIMEOUT_ASYNC, ref res)))
                        {
                            Log.Emit("dde-transact", "hConv", this.Handle, "item", itemName, "wFmt", wFmt, "wType", DDEML.GetTypeString(wType), "callback", callback != null, "id", res);
                            if(hData.Handle == IntPtr.Zero)
                            {
                                var errno = DDEML.DdeGetLastError(Client.idInst);
                                Log.Emit("dde-transact-failed", "error", DDEML.GetErrorString(errno) + " (" + errno.ToString() + ")");
                                if(callback != null)
                                    callback(itemName, false, null);
                                this.Disconnect();
                            }
                            else
                            {
                                if(callback != null)
                                {
                                    if(res == 0)
                                        callback(itemName, false, null);
                                    else if(callback != null & res != 0)
                                    {
                                        var id = new IntPtr(res);
                                        transactions.Add(id, new Transaction(id, callback));
                                    }
                                }
                            }
                        }
                    }
                }));
            }