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)); } } } } } })); }