Exemple #1
0
                public virtual void Advise(string topic, string item)
                    {
                        if (IsDisposed)
                            throw new ObjectDisposedException(GetType().ToString());
                        if (!IsRegistered)
                            throw new InvalidOperationException(Resources.NotRegisteredMessage);
                        if (topic == null)
                            throw new ArgumentNullException("topic");
                        if (topic.Length > Ddeml.MAX_STRING_SIZE)
                            throw new ArgumentException(Resources.StringParameterInvalidMessage, "topic");
                        if (item == null)
                            throw new ArgumentNullException("item");
                        if (item.Length > Ddeml.MAX_STRING_SIZE)
                            throw new ArgumentException(Resources.StringParameterInvalidMessage, "item");

                        // Assume the topic name and item name are wild.
                        var topicHandle = IntPtr.Zero;
                        var itemHandle = IntPtr.Zero;

                        // Create a string handle for the topic name if it is not wild.
                        if (topic != "*")
                            topicHandle = Ddeml.DdeCreateStringHandle(_InstanceId, topic, Ddeml.CP_WINANSI);

                        // Create a string handle for the item name if it is not wild.
                        if (item != "*")
                            itemHandle = Ddeml.DdeCreateStringHandle(_InstanceId, item, Ddeml.CP_WINANSI);

                        // Post an advise notification.  This will cause an XTYP_ADVREQ transaction for each conversation.
                        bool result = Ddeml.DdePostAdvise(_InstanceId, topicHandle, itemHandle);

                        // Free the string handles created earlier.
                        Ddeml.DdeFreeStringHandle(_InstanceId, itemHandle);
                        Ddeml.DdeFreeStringHandle(_InstanceId, topicHandle);

                        // Check the result to see if the post failed.
                        if (!result)
                            {
                                int error = Ddeml.DdeGetLastError(_InstanceId);
                                string message = Resources.AdviseFailedMessage;
                                message = message.Replace("${service}", _Service);
                                message = message.Replace("${topic}", topic);
                                message = message.Replace("${item}", item);
                                throw new DdemlException(message, error);
                            }
                    }