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. How to use a COM Interface Dll within C# code???

How to use a COM Interface Dll within C# code???

Scheduled Pinned Locked Moved C#
csharpcomtoolstutorialquestion
6 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.
  • L Offline
    L Offline
    lane0p2
    wrote on last edited by
    #1

    Hi All, i'm try to take the VB script and Dll in this article http://support.microsoft.com/kb/935635 and make the functionality work with C#. i can add the ExIpSec.dll type library and with the using statement (using EXIPSECLib) i can expose the Interfaces and i can some of them to work. but when i try to retrieve the list if IP addresses i just get System.object[]. i have tried converting this to a string[] but i get nothing back. can anyone tell how to correct call this dll? - DllImport does seem to work either!! Many Thanks, Phil

    Y D 2 Replies Last reply
    0
    • L lane0p2

      Hi All, i'm try to take the VB script and Dll in this article http://support.microsoft.com/kb/935635 and make the functionality work with C#. i can add the ExIpSec.dll type library and with the using statement (using EXIPSECLib) i can expose the Interfaces and i can some of them to work. but when i try to retrieve the list if IP addresses i just get System.object[]. i have tried converting this to a string[] but i get nothing back. can anyone tell how to correct call this dll? - DllImport does seem to work either!! Many Thanks, Phil

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      You may want to start at the beginning to understand how COM Interop [^]works

      Yusuf

      1 Reply Last reply
      0
      • L lane0p2

        Hi All, i'm try to take the VB script and Dll in this article http://support.microsoft.com/kb/935635 and make the functionality work with C#. i can add the ExIpSec.dll type library and with the using statement (using EXIPSECLib) i can expose the Interfaces and i can some of them to work. but when i try to retrieve the list if IP addresses i just get System.object[]. i have tried converting this to a string[] but i get nothing back. can anyone tell how to correct call this dll? - DllImport does seem to work either!! Many Thanks, Phil

        D Offline
        D Offline
        Dragonfly_Lee
        wrote on last edited by
        #3

        Well, without more info, we can not do anything with it. But all you did so far seems correct. In fact, .Net will wrap up the COM for you(if you add COM dll from the Visual Studio), we do not need to worry about the interface. I am intended to say maybe you miss something in your code, such as initialize certain parameter.

        :) I Love KongFu~

        L 1 Reply Last reply
        0
        • D Dragonfly_Lee

          Well, without more info, we can not do anything with it. But all you did so far seems correct. In fact, .Net will wrap up the COM for you(if you add COM dll from the Visual Studio), we do not need to worry about the interface. I am intended to say maybe you miss something in your code, such as initialize certain parameter.

          :) I Love KongFu~

          L Offline
          L Offline
          lane0p2
          wrote on last edited by
          #4

          the lines in the VB script are: Set objDsIpSec = CreateObject("ExIpSec.ExIpSecurity") objDsIpSec.BindToSmtpVsi "someSMTPserver", 1, "someDC" objDsIpSec.GetRelayIpList listToDisplayIp = objDsIpSec.IpGrant listToDisplayIp appears to be a string array. the lines in using in C# are: ExIpSecurity ipsec = new ExIpSecurity(); string[] s; ipsec.BindToSmtpVsi("someSMTPserver", 1, "someDC"); ipsec.GetRelayIpList(); s = ipsec.IPGrant.ToString().Split(' '); foreach (string i in s) { MessageBox.Show(i.ToString()); } if i run the VB script i get a list of IP address but if i run the C# code i get one popup box saying System.Object[] what am i doing wrong?

          D 1 Reply Last reply
          0
          • L lane0p2

            the lines in the VB script are: Set objDsIpSec = CreateObject("ExIpSec.ExIpSecurity") objDsIpSec.BindToSmtpVsi "someSMTPserver", 1, "someDC" objDsIpSec.GetRelayIpList listToDisplayIp = objDsIpSec.IpGrant listToDisplayIp appears to be a string array. the lines in using in C# are: ExIpSecurity ipsec = new ExIpSecurity(); string[] s; ipsec.BindToSmtpVsi("someSMTPserver", 1, "someDC"); ipsec.GetRelayIpList(); s = ipsec.IPGrant.ToString().Split(' '); foreach (string i in s) { MessageBox.Show(i.ToString()); } if i run the VB script i get a list of IP address but if i run the C# code i get one popup box saying System.Object[] what am i doing wrong?

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

            lane0p2 wrote:

            ipsec.BindToSmtpVsi("someSMTPserver", 1, "someDC"); ipsec.GetRelayIpList(); s = ipsec.IPGrant.ToString().Split(' ');

            Did you debug the code and check what the value of IPGrant is?

            :) I Love KongFu~

            L 1 Reply Last reply
            0
            • D Dragonfly_Lee

              lane0p2 wrote:

              ipsec.BindToSmtpVsi("someSMTPserver", 1, "someDC"); ipsec.GetRelayIpList(); s = ipsec.IPGrant.ToString().Split(' ');

              Did you debug the code and check what the value of IPGrant is?

              :) I Love KongFu~

              L Offline
              L Offline
              lane0p2
              wrote on last edited by
              #6

              hello, done it! when debugging i could see all the entries in IPGrant, the problem was converting the object array into a string array, i managed this with: ExIpSecurity ipsec = new ExIpSecurity(); ipsec.BindToSmtpVsi(someSMTPserver, 1, "someDC"); ipsec.GetRelayIpList(); object[] o = (object[])ipsec.IPGrant; string[] s = new string[o.Length]; Array arr = s; o.CopyTo(arr, 0); s = (string[])arr; foreach (string i in s) { sw.WriteLine(i); } thanks for your help mate, have a good weekend. Phil

              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