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. COM
  4. Calling Com object From C# to add 2 numbers

Calling Com object From C# to add 2 numbers

Scheduled Pinned Locked Moved COM
csharpvisual-studiocomhelptutorial
4 Posts 3 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.
  • C Offline
    C Offline
    Chrispie123
    wrote on last edited by
    #1

    Good Morning, I need to call a dll from C# that was generated by magic edeveloper. I think it is a C dll. It is a program that takes in 3 parameters all integers. Adds the first to and pass the sum to the 3rd parameter. I have registered the dll in windows and I can add a reference in visual studio via the Project  Add Reference menu. I have the following code in my project

    int a = 5;
    int b = 6;
    int sum = 0;
    double sumDouble = 0;
    sumdll.sumdllClass sdc = new sumdll.sumdllClass();
    sumDouble = sdc2.sumdll(ref a, ref b, ref sum);

    But if I run it I get the error

    Unable to cast COM object of type 'sumdll.sumdllClass' to interface type 'sumdll.Dsumdll'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3DC9FCBA-9E72-49AA-B597-F9B2603D5EEA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

    the following is available from the intellisense

    sumdll.sumdllClass sdc = new sumdll.
    Dsumdll which is an interface
    Sumdll which is an interface
    sumdllClas which is a class

    And in the line

    sumDouble = sdc2.sumdll(
    ref int input1, ref int input2, ref @input)

    Does anyone know I am getting this error? Or how to call the dll correctly. Regards, Christiaan Pieters

    C K M 3 Replies Last reply
    0
    • C Chrispie123

      Good Morning, I need to call a dll from C# that was generated by magic edeveloper. I think it is a C dll. It is a program that takes in 3 parameters all integers. Adds the first to and pass the sum to the 3rd parameter. I have registered the dll in windows and I can add a reference in visual studio via the Project  Add Reference menu. I have the following code in my project

      int a = 5;
      int b = 6;
      int sum = 0;
      double sumDouble = 0;
      sumdll.sumdllClass sdc = new sumdll.sumdllClass();
      sumDouble = sdc2.sumdll(ref a, ref b, ref sum);

      But if I run it I get the error

      Unable to cast COM object of type 'sumdll.sumdllClass' to interface type 'sumdll.Dsumdll'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3DC9FCBA-9E72-49AA-B597-F9B2603D5EEA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

      the following is available from the intellisense

      sumdll.sumdllClass sdc = new sumdll.
      Dsumdll which is an interface
      Sumdll which is an interface
      sumdllClas which is a class

      And in the line

      sumDouble = sdc2.sumdll(
      ref int input1, ref int input2, ref @input)

      Does anyone know I am getting this error? Or how to call the dll correctly. Regards, Christiaan Pieters

      C Offline
      C Offline
      Chrispie123
      wrote on last edited by
      #2

      Ok so I tried to do the same thing in VB.NET. I usally work in a console application for ease and once I have succeded I will convert or redo what every I have to do. The console application in VB.NET is by default in a module. If I do the following in VB.NET from the module

      Console.WriteLine("Start")
      Dim dllRef As New sumdll.sumdll() //Only this one method is available… It is indicated as an interface

          Dim a As Integer = 10
          Dim b As Integer = 18
          Dim c As Integer = 0
          Dim d As Double = 0.0
      
          d = dllRef.sumdll(a, b, c)
      
          Console.WriteLine("Done")
          Console.WriteLine(a)
          Console.WriteLine(b)
          Console.WriteLine(c)
          Console.WriteLine(d)
      

      Console.Read() But if I move the same code to a class I still get the same error as before. Why can’t this be called from a class? If I can get this to run from a class I am sure I will be able to call this from C#. Thanks, Christiaan

      1 Reply Last reply
      0
      • C Chrispie123

        Good Morning, I need to call a dll from C# that was generated by magic edeveloper. I think it is a C dll. It is a program that takes in 3 parameters all integers. Adds the first to and pass the sum to the 3rd parameter. I have registered the dll in windows and I can add a reference in visual studio via the Project  Add Reference menu. I have the following code in my project

        int a = 5;
        int b = 6;
        int sum = 0;
        double sumDouble = 0;
        sumdll.sumdllClass sdc = new sumdll.sumdllClass();
        sumDouble = sdc2.sumdll(ref a, ref b, ref sum);

        But if I run it I get the error

        Unable to cast COM object of type 'sumdll.sumdllClass' to interface type 'sumdll.Dsumdll'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3DC9FCBA-9E72-49AA-B597-F9B2603D5EEA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

        the following is available from the intellisense

        sumdll.sumdllClass sdc = new sumdll.
        Dsumdll which is an interface
        Sumdll which is an interface
        sumdllClas which is a class

        And in the line

        sumDouble = sdc2.sumdll(
        ref int input1, ref int input2, ref @input)

        Does anyone know I am getting this error? Or how to call the dll correctly. Regards, Christiaan Pieters

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        I can only give you the advice to use better names for your stuff. You are mixing interfaces and classes. :((

        Press F1 for help or google it. Greetings from Germany

        1 Reply Last reply
        0
        • C Chrispie123

          Good Morning, I need to call a dll from C# that was generated by magic edeveloper. I think it is a C dll. It is a program that takes in 3 parameters all integers. Adds the first to and pass the sum to the 3rd parameter. I have registered the dll in windows and I can add a reference in visual studio via the Project  Add Reference menu. I have the following code in my project

          int a = 5;
          int b = 6;
          int sum = 0;
          double sumDouble = 0;
          sumdll.sumdllClass sdc = new sumdll.sumdllClass();
          sumDouble = sdc2.sumdll(ref a, ref b, ref sum);

          But if I run it I get the error

          Unable to cast COM object of type 'sumdll.sumdllClass' to interface type 'sumdll.Dsumdll'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3DC9FCBA-9E72-49AA-B597-F9B2603D5EEA}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

          the following is available from the intellisense

          sumdll.sumdllClass sdc = new sumdll.
          Dsumdll which is an interface
          Sumdll which is an interface
          sumdllClas which is a class

          And in the line

          sumDouble = sdc2.sumdll(
          ref int input1, ref int input2, ref @input)

          Does anyone know I am getting this error? Or how to call the dll correctly. Regards, Christiaan Pieters

          M Offline
          M Offline
          Md Marufuzzaman
          wrote on last edited by
          #4

          Well.. Do you try to register this dll in to the GAC?

          Thanks Md. Marufuzzaman


          Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.

          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