Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# COM Interop

C# COM Interop

Scheduled Pinned Locked Moved C#
comcsharphelptutorial
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vijjuuu
    wrote on last edited by
    #1

    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.

    B M L D 4 Replies Last reply
    0
    • V Vijjuuu

      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.

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      COM interop is supposed to work with normal .Net events (i.e. event EventHandler Calculate), isn't it? The problem here might be VB6 ...

      1 Reply Last reply
      0
      • V Vijjuuu

        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.

        M Offline
        M Offline
        Mirko1980
        wrote on last edited by
        #3

        You have to play a bit with interfaces. Look here for a sample.

        1 Reply Last reply
        0
        • V Vijjuuu

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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:

          1 Reply Last reply
          0
          • V Vijjuuu

            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.

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            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)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups