public static int Initialize(Ddeml.DdeCallback pfnCallback, int afCmd) { lock (_Table) { // Initialize a DDEML instance. int instanceId = 0; Ddeml.DdeInitialize(ref instanceId, pfnCallback, afCmd, 0); if (instanceId != 0) { // Make sure this thread has an IMessageFilter on it. LocalDataStoreSlot slot = Thread.GetNamedDataSlot(DataSlot); if (Thread.GetData(slot) == null) { InstanceManager filter = new InstanceManager(); Application.AddMessageFilter(filter); Thread.SetData(slot, filter); } // Add an entry to the table that maps the instance identifier to the current thread. _Table.Add(instanceId, Ddeml.GetCurrentThreadId()); } return instanceId; } }