コード例 #1
0
        public void Advise(string topic, string item)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().ToString());
            }
            if (!IsRegistered)
            {
                throw new InvalidOperationException("NotRegisteredMessage");
            }
            if (topic == null || topic.Length > Ddeml.MAX_STRING_SIZE)
            {
                throw new ArgumentNullException("topic");
            }
            if (item == null || item.Length > Ddeml.MAX_STRING_SIZE)
            {
                throw new ArgumentNullException("item");
            }
            // Assume the topic name and item name are wild.
            IntPtr topicHandle = topic != "*" ? Ddeml.DdeCreateStringHandle(_InstanceId, topic, Ddeml.CP_WINANSI) : IntPtr.Zero;
            IntPtr itemHandle  = item != "*" ? Ddeml.DdeCreateStringHandle(_InstanceId, item, Ddeml.CP_WINANSI) : IntPtr.Zero;

            // Check the result to see if the post failed.
            if (!Ddeml.DdePostAdvise(_InstanceId, topicHandle, itemHandle))
            {
                int error = Ddeml.DdeGetLastError(_InstanceId);
                var msg   = Ddeml.DDEGetErrorMsg(error); if (msg != null)
                {
                }
            }
            Ddeml.DdeFreeStringHandle(_InstanceId, itemHandle);
            Ddeml.DdeFreeStringHandle(_InstanceId, topicHandle);
        }