C# COM Interop
-
Hi All, i googled how we can added events in C# class for COM Interop that can be called in VB6.0 but not able to find out any article that help me. if any one tried it before then pls guide me. here is my code. public interface ICalculator { // I guess we need to add a event here but i am not sure . int Add(int Number1, int Number2); } public class ManagedClass:ICalculator { public int Add(int Number1,int Number2) { // I want to raise an event here so that this event should be consumed in VB return Number1+Number2; } } i done all the step to make the dll to be used in VB.
-
Hi All, i googled how we can added events in C# class for COM Interop that can be called in VB6.0 but not able to find out any article that help me. if any one tried it before then pls guide me. here is my code. public interface ICalculator { // I guess we need to add a event here but i am not sure . int Add(int Number1, int Number2); } public class ManagedClass:ICalculator { public int Add(int Number1,int Number2) { // I want to raise an event here so that this event should be consumed in VB return Number1+Number2; } } i done all the step to make the dll to be used in VB.
-
Hi All, i googled how we can added events in C# class for COM Interop that can be called in VB6.0 but not able to find out any article that help me. if any one tried it before then pls guide me. here is my code. public interface ICalculator { // I guess we need to add a event here but i am not sure . int Add(int Number1, int Number2); } public class ManagedClass:ICalculator { public int Add(int Number1,int Number2) { // I want to raise an event here so that this event should be consumed in VB return Number1+Number2; } } i done all the step to make the dll to be used in VB.
-
Hi All, i googled how we can added events in C# class for COM Interop that can be called in VB6.0 but not able to find out any article that help me. if any one tried it before then pls guide me. here is my code. public interface ICalculator { // I guess we need to add a event here but i am not sure . int Add(int Number1, int Number2); } public class ManagedClass:ICalculator { public int Add(int Number1,int Number2) { // I want to raise an event here so that this event should be consumed in VB return Number1+Number2; } } i done all the step to make the dll to be used in VB.
You'd need to declare the object
WithEvents
in VB6, otherwise VB6 won't hook those up. Microsoft made a toolkit[^] to make interop between VB6 and .NET a lot easier. I suggest you download it and have a look. There's also a CodeProject article[^] on the subject.Bastard Programmer from Hell :suss:
-
Hi All, i googled how we can added events in C# class for COM Interop that can be called in VB6.0 but not able to find out any article that help me. if any one tried it before then pls guide me. here is my code. public interface ICalculator { // I guess we need to add a event here but i am not sure . int Add(int Number1, int Number2); } public class ManagedClass:ICalculator { public int Add(int Number1,int Number2) { // I want to raise an event here so that this event should be consumed in VB return Number1+Number2; } } i done all the step to make the dll to be used in VB.
I'm not sure about COM interop stuff as I've never needed it - but events are quite straight forward to add:
public interface ICalculator
{
event EventHandler CalculationPerformed;
event EventHandler<int> CalculatedResult;int Add(int Number1, int Number2);
}
public class ManagedClass : ICalculator
{
public event EventHandler CalculationPerformed;
public event EventHandler<int> CalculatedResult;public int Add(int number1, int number2) { int result = number1 + number2; OnCalculationPerformed(EventArgs.Empty); OnCalculatedResult(new EventArgs<int>(result)); return result; } protected virtual void OnCalculationPerformed(EventArgs e) { EventHandler eh = CalculationPerformed; if (eh != null) eh(this, e); } protected virtual void OnCalculatedResult(EventArgs<int> e) { EventHandler<int> eh = CalculatedResult; if (eh != null) eh(this, e); }
}
public delegate void EventHandler<T>(object sender, EventArgs<T> e);
public class EventArgs<T> : EventArgs
{
private T value;public EventArgs(T value) { this.value = value; } public T Value { get { return value; } }
}
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)