/// <summary> /// Initiates a conversation. /// </summary> /// <param name="service">Service (or application name) we're connecting to.</param> /// <param name="topic">Topic to request the server for.</param> internal DdeConversation(Dde dde, string service, string topic) { _dde = dde; /* * // Describe the conversation * Dde.CONVCONTEXT cc; * cc.cb = (uint)Marshal.SizeOf(typeof(Dde.CONVCONTEXT)); * cc.wFlags = 0u; * cc.wCountryID = 0u; * cc.iCodePage = Win32Declarations.CP_WINANSI; * cc.dwLangID = 0u; * cc.dwSecurity = 0u; * cc.qos.Length = (uint)Marshal.SizeOf(typeof(Dde.SECURITY_QUALITY_OF_SERVICE)); * cc.qos.ImpersonationLevel = Dde.SECURITY_IMPERSONATION_LEVEL.SecurityAnonymous; * cc.qos.ContextTrackingMode = Dde.SECURITY_CONTEXT_TRACKING_MODE.SECURITY_STATIC_TRACKING; * cc.qos.EffectiveOnly = 1; */ using (DdeString dsService = new DdeString(_dde, service)) using (DdeString dsTopic = new DdeString(_dde, topic)) _handle = Dde.DdeConnect(_dde.Instance, dsService.Handle, dsTopic.Handle, IntPtr.Zero); if (_handle == IntPtr.Zero) { throw new DdeException("Could not start the DDE conversation.", _dde.GetLastError()); } }
/// <summary> /// Initiates a synchronous DDE transaction, using the timeout value specified. /// If the timeout expires, an exception is thrown. /// </summary> /// <param name="item">Item name for which the transaction is executed.</param> /// <param name="data">Data to be exchanged during the transaction.</param> /// <param name="timeout">Specifies the maximum length of time, in milliseconds, that the client will wait for a response from the server application in a synchronous transaction.</param> public void StartTransaction(string item, string data, DWORD timeout) { Dde.CheckOwnerThread(); byte[] arDataBuffer = data != null?Encoding.ASCII.GetBytes(data) : null; DWORD dwResult = 0; using (DdeString dsItem = new DdeString(_dde, item)) { if (Dde.DdeClientTransaction(arDataBuffer, (uint)(arDataBuffer != null ? arDataBuffer.Length : 0), _handle, dsItem.Handle, 0, Dde.DdeTransaction.XTYP_EXECUTE, timeout, ref dwResult) == IntPtr.Zero) { throw new DdeException("Could start a DDE transaction.", _dde.GetLastError()); } } }