简体   繁体   中英

how can i call the external custom .dll file written in c# from Delphi Script?

using System;

namespace Example1
{
class Program
  {
   public static void portAvailable(IPAddress ipa,int port)
    {
try
{
      System.Net.Sockets.Socket sock = new    
      System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
      System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
  sock.Connect(ipa, portno);
  if (sock.Connected == true)  // Port is in use and connection is successful
  MessageBox.Show("Port is Closed");
  sock.Close();

}
catch (System.Net.Sockets.SocketException ex)
{
if (ex.ErrorCode == 10061)  // Port is unused and could not establish connection 
     MessageBox.Show("Port is Open!");
else
     MessageBox.Show(ex.Message);
}

  }


 static void Main(string[] args)
  { 
            string hostName=Dns.GetHostname();
    int port=Convert.ToInt32(Console.ReadLine());
    IPAddress ipa = (IPAddress) Dns.GetHostAddresses(hostName)[0];
             portAvailable(ipa,port);


  }
 }
}

how can i call portAvailable() function from this .dll in Delphi for InnoSetup? what's wrong with code posted above ?i tried to access this .dll in my InnoSetup but when user entering port number it is not checking. i supposed to install the setup in the available ports only.when the user enters the port which is in us then it should notify to ask for other port number.please solve this problem

  function portAvailable(
      ipa :IPAddress;
      port : int;):void;external 'Program.dll';

i am trying to call the function in Program.dll here.

.NET DLL are not native DLL so you can't call methods directly usually, you have to expose them somehow using either a mixed mode C++/CLI assembly or COM.

I'm not sure what COM interop Inno has (if any). You might find it easy to just build out an executable and call it from Inno with command line arguments.

Addendum:

There's also a third party package called Unmanaged Exports you can try which works similar to DllImport , although I've not tried this myself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM