C#調用Delphi Dll返回字符串的示例(使用Move才能拷貝字符串)


//----------------------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 ASourceStringBuilder ADest, int ADestSize);
 
private void button1_Click(object senderEventArgs e)
{
    StringBuilder vDest = new StringBuilder(1024);
    GetSqlData("Zswang", vDest, 1024);
    Text = vDest.ToString();
}
 
http://blog.csdn.net/zswang/article/details/1615264


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM