public void SearchComplete(int lFindData) { IUPnPDeviceFinderCallback callback = (IUPnPDeviceFinderCallback)connection.Target; if (callback == null) { return; } callback.SearchComplete(lFindData); }
public void DeviceRemoved(int lFindData, string bstrUDN) { IUPnPDeviceFinderCallback callback = (IUPnPDeviceFinderCallback)connection.Target; if (callback == null) { return; } callback.DeviceRemoved(lFindData, bstrUDN); }
public void DeviceAdded(int lFindData, UPnPDevice pDevice) { try { IUPnPDeviceFinderCallback callback = (IUPnPDeviceFinderCallback)connection.Target; if (callback == null) { return; } callback.DeviceAdded(lFindData, pDevice); } finally { Marshal.ReleaseComObject(pDevice); } }
// Initiate UPNP discovery void SearchForDevices() { IntPtr pCB; // Create an instance of a UPNPFinder Type tFinder = Type.GetTypeFromCLSID(CLSID_UPnPFinder); object oInst = Activator.CreateInstance(tFinder); _finder = (IUPnPDeviceFinder)oInst; // Create a callback object _finderCallback = new Callback(this); pCB = Marshal.GetComInterfaceForObject(_finderCallback, typeof(IUPnPDeviceFinderCallback)); // Pin the callback to ensure it does not get garbage-collected _hCallback = GCHandle.Alloc(_finderCallback, GCHandleType.Pinned); // Start search _asyncFind = _finder.CreateAsyncFind("upnp:rootdevice", 0, pCB); Debug.WriteLine("Starting search"); _finder.StartAsyncFind(_asyncFind); }
public DeviceFinderCallback(IUPnPDeviceFinderCallback outer) { connection = new WeakReference(outer); }