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