PDA

Click to See Complete Forum and Search --> : [RESOLVED] callback from com doesnt work


madsun
Jan 25th, 2007, 08:28 AM
Hi
I have an activex with some callbacks..How can get my values...??

public abstract virtual System.Int32 GetValue ( System.Int32 myId , System.Object Value )

System.Object Value is the callback...

So..i can do f.ex
int id = 5000;
object a="";

myControl.getValue(id,ref a);

...however, this gives me datatype mismatch..
The callback is supposed to be a "ref object" type, how can i get this to work?

jmcilhinney
Jan 25th, 2007, 05:05 PM
Methods arguments that require callbacks are delegates in .NET code. You can't pass a string to an argument that expects a delegate. An empty string is not a null value. It is a string with no characters in it, but it is still very definitely a string. If you don't want to p[ass a callback method, assuming that the method you're calling will allow it, then you need to explicitly pass null. Otherwise you need to create an appropriate delegate and pass that.

A callback is a method that gets called from the remote location. In .NET a delegate is an object that contains a reference to a method. You pass the delegate to the method argument and the method it refers to is what gets called from the remote location. If you want more information delegates and their use just search MSDN.

madsun
Jan 26th, 2007, 02:45 AM
Ay, very enlightning :-)
Ill check it out and come back if i still have no clue on what to do

Madsun

madsun
Jan 27th, 2007, 01:27 PM
figured it out... :-)

object a = null;
myControl.getValue(1000,ref a);

That solves it, thanks for the tip!