473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

COM Events through C# using callback (UPnPLib)

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
Nov 17 '05 #1
1 7088
nelson
1
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
Do you already have the solution for the problem? Can anybody tell me what is the solution?
thunk you all
May 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: HankC | last post by:
Greetings: I'm been programming Delphi for a while and am trying to get into the Python mindset. In Delphi, you can have a component class that has properties, methods, and events. Properties...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
2
by: Stampede | last post by:
Hi guys 'n' girls, I want to use callback methods when using BeginInvoke on some events. So far no problem, but know I thought about what could happen (if I'm not completly wrong). Lets say an...
3
by: Chris | last post by:
Hi, what is the difference between using events and delegates (apart from the syntax) ? have a look at following (working) programs please (you can just copy/paste and build it) : First...
20
by: David Levine | last post by:
I ran into a problem this morning with event accessor methods that appears to be a bug in C# and I am wondering if this a known issue. public event SomeDelegateSignature fooEvent; public event...
15
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched,...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that...
0
by: Gianmaria Iaculo - NVENTA | last post by:
Hi there, i found a nice article about a custom implementation of events by Duncan Booth here: http://www.suttoncourtenay.org.uk/duncan/accu/pythonpatterns.html#observer The code is here: ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.