【发布时间】:2010-05-28 12:28:36
【问题描述】:
如何在Delphi制作的Win32 DLL文件中使用C#函数。什么时候函数参数是自定义的delphi对象?
Delphi 中的函数定义:
function GetAttrbControls( Code : PChar;
InputList: TItemList;
var Values : TValArray): Boolean; stdcall; export;
使用的类型:
type
TItem = packed record
Code : PChar;
ItemValue: Variant;
end;
TItemList = array of TItem;
TValArray = array of PChar;
C# 中的示例(不起作用):
[StructLayout(LayoutKind.Sequential)]
public class Input
{
public string Code;
public object ItemValue;
};
[DllImport("Filename.dll", EntryPoint = "GetValues", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern bool GetValues(string Code, Input[] InputList, ref StringBuilder[] Values);
【问题讨论】: