[测速]c#调用delphi的dll的方法

时间:2017-02-07  来源:Delphi  阅读:

几个关键技术点:

1、C#要以非托管方式调用DLL;
2、C#把整理好的画图数据生成事先定义好格式的XML文件,传给DLL;
3、DLL解析XML文件,根据相应格式,要求,画图;
4、DLL输出GIF文件(经过比较GIF图像失真率小,且文件大小最小);
5、C#装载GIF文件,传到前台展示。

 

library Icdll;

uses
  SysUtils;

 

   function Check22:Pchar;stdcall;
   begin
   result:="ok";
   end;

exports
  Check22;
begin
end.


 

2.在c#中进行调用。

using System.Runtime.InteropServices; //必须引用
namespace TestDll
{
    public partial class Form1 : Form
    {
        [DllImport("Icdll.dll")]
        public static extern StringBuilder Check22();
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

              StringBuilder result= Check22(); //这里result就是返回值。


        }

    }

实例后

2007年05月22日 星期二 下午 05:46
//----------------------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();
}

   小结:进行字符串返回,1.在delphi返回是pchar类型,c#中接收用StringBuilder接收,没有什么特别的注意事项,和其它的DLL基本一样,注意string换成PChar就可以了

[测速]c#调用delphi的dll的方法

http://m.bbyears.com/wangyezhizuo/30315.html

推荐访问:藏宝阁 菜鸟教程 创客贴 草料二维码 cctv5 csdn cnki colg
相关阅读 猜你喜欢
本类排行 本类最新