C # There are two solutions to call the Delphi interface:
1. Compile the Delphi program into a COM component and reference the COM component in C.
II. The DLL file of the unmanaged call Dephi.
Here we will mainly explain the second method. before talking about the second method, we will first explain DllImport.
DllImport is an attribute class in the System. Runtime. InteropServices namespace. Its function is to provide necessary call information for functions exported from unmanaged DLL.
When the DllImport attribute is applied to a method, the dll name containing the entry point must be provided at least.
The definition of DllImport is as follows:
Code 1 [AttributeUsage (AttributeTargets. Method)]
2 public class DllImportAttribute: System. Attribute
3 {
4 public DllImportAttribute (string dllName ){...} // The positioning parameter is dllName.
5 public CallingConvention; // call convention for the entry point
6 public CharSet; // string used for the entry point
7 public string EntryPoint; // entry point name
8 public bool ExactSpelling; // whether the spelling must be exactly the same as the indicated entry point. The default value is false.
9 public bool PreserveSig; // whether the signature of the method is retained or converted
10 public bool SetLastError; // the return value of the FindLastError method is stored here
11 public string Value {get {...} }
12}
13
The above DLL name sometimes needs to write the path such as [DllImport (@ "C: OJBinJudge. dll")] so that the absolute path of the specified DLL can be loaded normally.
If there is no path, DllImport will automatically find the location in order:
1. Directory of exe
2. System32 directory
3. Environment Variable directory
Therefore, you only need to copy the referenced DLL to these three directories, and you do not need to write the path.
Note :&