예제 #1
0
파일: Dde.cs 프로젝트: mo5h/omeo
        /// <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());
            }
        }
예제 #2
0
파일: Dde.cs 프로젝트: mo5h/omeo
        /// <summary>
        /// Initializes the object from a handle, takes ownership over the handle, and extracts a string value as it's needed.
        /// <c>Null</c> is a valid value for the handle, will cause a <c>Null</c> string to be returned.
        /// </summary>
        public DdeString(Dde dde, HSZ handle)
        {
            _dde    = dde;
            _handle = handle;

            _dde.KeepStringHandle(handle);
            _release = handle != IntPtr.Zero;
        }
예제 #3
0
파일: Dde.cs 프로젝트: mo5h/omeo
 public void Dispose()
 {
     if ((_handle != IntPtr.Zero) && (_dde != null))
     {
         if (!Dde.DdeDisconnect(_handle))
         {
             throw new DdeException("Could not terminate the conversation.", _dde.GetLastError());
         }
         _handle = IntPtr.Zero;
         _dde    = null;
     }
     GC.SuppressFinalize(this);
 }
예제 #4
0
파일: Dde.cs 프로젝트: mo5h/omeo
        /// <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());
                }
            }
        }
예제 #5
0
파일: Dde.cs 프로젝트: mo5h/omeo
 /// <summary>
 /// Initializes the object from a string. The handle will be generated upon a request.
 /// <c>Null</c> is a valid value for a string, will cause a <c>Null</c> handle to be returned.
 /// </summary>
 public DdeString(Dde dde, string text)
 {
     _string = text;
     _dde    = dde;
 }