public string Register(string service) { if (IsRegistered || _InstanceId != 0) { throw new InvalidOperationException("AlreadyRegisteredMessage"); } if (service == null || service.Length > Ddeml.MAX_STRING_SIZE) { throw new ArgumentNullException("service"); } _Service = service; _ConversationTable.Clear(); _InstanceId = Initialize(Ddeml.APPCLASS_STANDARD); _ServiceHandle = Ddeml.DdeCreateStringHandle(_InstanceId, _Service, Ddeml.CP_WINANSI); // Register the service name. if (Ddeml.DdeNameService(_InstanceId, _ServiceHandle, IntPtr.Zero, Ddeml.DNS_REGISTER) == IntPtr.Zero) { Ddeml.DdeFreeStringHandle(_InstanceId, _ServiceHandle); _ServiceHandle = IntPtr.Zero; } // If the service handle is null then the service name could not be registered. if (_ServiceHandle == IntPtr.Zero) { int error = Ddeml.DdeGetLastError(_InstanceId); return(Ddeml.DDEGetErrorMsg(error)); } return(null); }
public void Unregister() { Ddeml.DdeNameService(_InstanceId, _ServiceHandle, IntPtr.Zero, Ddeml.DNS_UNREGISTER); // Free the service string handle. Ddeml.DdeFreeStringHandle(_InstanceId, _ServiceHandle); // Indicate that the service name is no longer registered. _ServiceHandle = IntPtr.Zero; _InstanceId = 0; }