У меня есть dll С#, и я хочу использовать ее в своем коде Delphi, перед этим dll должна быть зарегистрирована с помощью regasm. Я пытался зарегистрировать эту dll, но постоянно получаю предупреждение ниже:
Microsoft Windows [Версия 6.1.7601] Copyright (c) Microsoft Corporation, 2009 г. Все права защищены.
C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm c:\debug\modbusdll.dll
Microsoft (R) .NET Framework Assembly Registration Utility 4.0.30319.1
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.
RegAsm : warning RA0000 : No types were registered
C:\Windows\Microsoft.NET\Framework\v4.0.30319>
В Интернете я обнаружил, что для параметра COMVisible установлено значение true в AssemblyInfo.cs, и это решит эту проблему. Но для него уже установлено значение true, и у меня все еще возникает эта проблема.
Код С# выглядит следующим образом:
пространство имен ModbusDLL { //// {0E32E465-79A4-4251-AF02-FEBE05198F76}
[Guid("0E32E465-79A4-4251-AF02-FEBE05198F76")]
public interface IModbus
{
bool setABC(int a);//{GUID:f7f14b6f-e8da-4562-baf7-aa6846861f66}
byte[] getDiscreteInput(ushort id, byte unit, ushort startaddress, ushort numinputs);//{GUID:f7f14b6f-e8da-4562-baf7-aa6846861f67}
byte[] getInputRegister(ushort id, byte unit, ushort startaddress, ushort numinputs);//{GUID:f7f14b6f-e8da-4562-baf7-aa6846861f68}
byte[] getHoldingRegister(ushort id, byte unit, ushort startaddress, ushort numinputs);//{GUID:f7f14b6f-e8da-4562-baf7-aa6846861f69}
}
[Guid("0E32E465-79A4-4251-AF02-FEBE05198F77")]
public class ModbusImplementor:IModbus
{
ModbusTcpClient m=null;
public ModbusImplementor()
{
//m = new ModbusTcpClient(ip, port);
}
/*public ModbusImplementor(string ip, ushort port)
{
m = new ModbusTcpClient(ip, port);
}*/
public bool setABC(int a)
{
int A = a;
return true;
}
public byte[] getDiscreteInput(ushort id, byte unit, ushort startaddress, ushort numinputs)
{
//2,
byte[] values =new byte[15];
m.ReadDiscreteInputs(id, unit, startaddress, numinputs, ref values);
return values;
}
public byte[] getInputRegister(ushort id, byte unit, ushort startaddress, ushort numinputs)
{
byte[] values = new byte[15];
m.ReadInputRegister(id, unit, startaddress, numinputs, ref values);
return values;
}
public byte[] getHoldingRegister(ushort id, byte unit, ushort startaddress, ushort numinputs)
{
byte[] values = new byte[15];
m.ReadHoldingRegister(id, unit, startaddress, numinputs, ref values);
return values;
}
~ ModbusImplementor()
{
m.Disconnect();
m.Dispose();
}
}
}
AssemblyInfo.cs-
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ModbusDLL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("ModbusDLL")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f7f14b6f-e8da-4562-baf7-aa6846861f66")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Codebase
? Попробуйте зарегистрировать его с помощью этого переключателя и посмотрите... - person Rahul Kishore   schedule 07.09.2016