C#呼叫Delphi Dll返回字串的示例
阿新 • • 發佈:2018-12-30
//----------------------Delphi-------------------
procedure GetSqlData(ASource: PChar; ADest: PChar; ADestSize: Integer); stdcall;
var
S: string;
begin
if ASource = nil then Exit;
S := Format('%s 路過!',[ASource]);
Move(S[1], ADest^, Min(ADestSize, Length(S)+1));
end;{ GetSqlData }
exports
GetSqlData ;
//----------------------C#-------------------
[DllImport(@"TempLib.dll")]
public static extern void GetSqlData(string ASource, StringBuilder ADest, int ADestSize);
private void button1_Click(object sender, EventArgs e)
{
StringBuilder vDest = new StringBuilder(1024);
GetSqlData("Zswang", vDest, 1024 );
Text = vDest.ToString();
}