访问量: 33844次,访客数: 28925人,浏览量: 1次 
首页  编辑  

C#调用Delphi Dll返回字符串的示例

Tags: /C#/API调用/   Date Created: Tue Jun 10 2008 01:18:08 GMT+0000 (Coordinated Universal Time)

//----------------------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#-------------------

using System . Runtime . InteropServices;

[ 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();

}