COM Events through C# using callback (UPnPLib)

G

Guest

Im fairly new to C# and am having a few problems getting events to fire when
using COM interop with C#, can someone take a quick look at the following
example and give me a pointer as to why the callback never gets called? The
example is just supposed to list UPnp root devices, I have run netmon and
seen the UPnp responses coming back to my PC, its just I never see the
callback getting called.

Thanks in advance for any help/advice

using System;
using System.Text;
using UPNPLib;
using System.Runtime.InteropServices;

namespace Test1
{
public delegate void CallBack(UPnPDevice device, string udn, uint i);

class Class1
{
[STAThread]
static void Main(string[] args)
{
CallBack cb = new CallBack(Class1.upnpcallback);

UPNPLib.UPnPDeviceFinderClass df = new UPnPDeviceFinderClass();

int myDevID = 0;
string typeURI = "upnp:rootdevice";

myDevID = df.CreateAsyncFind(typeURI, 0, cb);
df.StartAsyncFind(myDevID);
Console.WriteLine("Searching for devices of type {0}.", typeURI);
Console.ReadLine();
Console.WriteLine("Done.");
}

public static void upnpcallback(UPnPDevice device, string udn, uint i)
{
Console.WriteLine("upnpcallback!");
switch(i)
{
case 0: //device added
Console.WriteLine("Device added: {0}", device.FriendlyName);
break;
case 1: // device removed
Console.WriteLine("Device removed: {0}", udn);
break;
case 2: // search completed
Console.WriteLine("Search Completed");
break;
default:
Console.WriteLine("Default");
break;
}
}
}
}


I must have tried about a 1000 variants of the above code and still cannot
get the callback to fire so it must be something blatently obvious im not
doing :p

I have also tried different installing callbacks on different COM objects
and not been able to get them to fire.

Thnx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top