delphi dll编写与调用
dll代码:
mydll.dpr
library mydll; uses
System.SysUtils,
System.Classes,
uFunction in 'uFunction.pas'; {$R *.res} exports
AddInt,
AddStr,
AddDouble,
Add; end.
uFunction.pas
unit uFunction; interface uses
System.SysUtils, System.Classes, Winapi.Messages; function AddInt(a1: Integer; a2: Integer): Integer; stdcall;
function AddStr(a1: PWideChar; a2: PWideChar): PWideChar; stdcall;
function AddDouble(a1: Double; a2: Double): Double; stdcall;
function Add(a1: Integer; a2: Integer): PWideChar; stdcall; implementation function AddInt(a1: Integer; a2: Integer): Integer; stdcall;
begin
Result := a1 + a2;
end; function AddStr(a1: PWideChar; a2: PWideChar): PWideChar; stdcall;
begin
Result := PWideChar(string(a1) + string(a2));
end; function AddDouble(a1: Double; a2: Double): Double; stdcall;
begin
result:= a1 + a2;
end; function Add(a1: Integer; a2: Integer): PWideChar; stdcall;
begin
Result := PWideChar((a1 + a2).ToString);
end; end.
delphi调用:
unit uMain; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; function AddInt(a1: Integer; a2: Integer): Integer; stdcall; external 'mydll.dll';
function AddStr(a1: PWideChar; a2: PWideChar): PWideChar; stdcall; external 'mydll.dll';
function AddDouble(a1: Double; a2: Double): Double; stdcall; external 'mydll.dll';
function Add(a1: Integer; a2: Integer): PWideChar; stdcall; external 'mydll.dll'; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(AddInt(, ).ToString);
end; procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage(string(AddStr('hello ', 'world')));
end; procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage(AddDouble(5.1, 6.1).ToString);
end; procedure TForm1.Button4Click(Sender: TObject);
begin
ShowMessage(string(Add(, )));
end; procedure TForm1.FormCreate(Sender: TObject);
begin
Position := poScreenCenter;
end; end.
c#调用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace hello_dll
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} [DllImport("mydll.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern int AddInt(int a1, int a2); [DllImport("mydll.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr AddStr(string a1, string a2); [DllImport("mydll.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern double AddDouble(double a1, double a2); [DllImport("mydll.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr Add(int a1, int a2); private void Form1_Load(object sender, EventArgs e)
{
StartPosition = FormStartPosition.CenterScreen;
} private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(AddInt(, ).ToString());
} private void button2_Click(object sender, EventArgs e)
{
IntPtr ptr = AddStr("hello ", "world");
string str = Marshal.PtrToStringUni(ptr);
MessageBox.Show(str);
} private void button3_Click(object sender, EventArgs e)
{
MessageBox.Show(AddDouble(5.1, 6.1).ToString());
} private void button4_Click(object sender, EventArgs e)
{
IntPtr ptr = Add(, );
string str = Marshal.PtrToStringUni(ptr);
MessageBox.Show(str);
}
}
}
delphi dll编写与调用的更多相关文章
- DLL编写与调用全解
DLL编写与调用全解 DELPHI学习 2008-12-23 22:52 阅读8 评论0 字号: 大 中 小 第一章 为什么要使用动态链接库(DLL) top 提起DLL您一定不会 ...
- VB.NET中的DLL编写和调用的最简单示例
DLL(动态链接库)是一个很有用的东西,在开发大项目的时候显得非常重要,因为多人合作开发时,可以给每个人分配一个任务,用DLL完成,最后组合起来,就不会出现互相冲突的问题.这里给出最简单的DLL编写与 ...
- delphi dll创建及调用
第一章 DLL简单介绍由于在目前的学习工作中,需要用到DLL文件,就学习了下,在这里作个总结.首先装简单介绍下DLL:1,减小可执行文件的大小DLL技术的产生有很大一部分原因是为了减小可执行文件的大小 ...
- Delphi编写DLL供C#调用的实例
Delphi中编写的Dll: library TestDLL; { Important note about DLL memory management: ShareMem must be the f ...
- delphi 基础之三 编写和调用dll文件
delphi 编写和调用dll文件 Windows 的执行文件可以划分为两种形式程序和动态连接库 (DLLs).一般程序运行是用.EXE文件,但应用程序有时也可以调用存储在DLL的函数. 在如下几 ...
- delphi编写与调用DLL(delphi7下测试通过)
http://blog.sina.com.cn/s/blog_4dbbf76f01000anz.html delphi编写DLL 下面在delphi中编写一个简单的dll,在该dll中只有一个max函 ...
- Delphi DLL的创建、静态及动态调用
转载:http://blog.csdn.net/welcome000yy/article/details/7905463 结合这篇博客:http://www.cnblogs.com/xumenger/ ...
- Delphi 中的DLL 封装和调用对象技术(刘艺,有截图)
Delphi 中的DLL 封装和调用对象技术本文刊登2003 年10 月份出版的Dr.Dobb's 软件研发第3 期刘 艺摘 要DLL 是一种应用最为广泛的动态链接技术但是由于在DLL 中封装和调用对 ...
- Delphi 动态与静态调用DLL(最好的资料)
摘要:本文阐述了 Windows 环境下动态链接库的概念和特点,对静态调用和动态调用两种调用方式作出了比较,并给出了 Delphi 中应用动态链接库的实例. 一.动态链接库的概念 动态链接库( ...
随机推荐
- CTU Open Contest 2019 AB题
小菜鸡飘过 A: Beer Barrels 题意:给出四个整数:A,B,K,C,:A,B,C都是大于0的个位数,问在所有仅有A或者B组成的K位数中,数字C的个数是多少 思路: 1.先考虑特殊情况: ( ...
- Intend之Date的几个功能
封装为一个方法 1.跳转到拨号页面 //跳转到拨号页面的方法 protected void takeCall(String info){ Intent intent=new Intent(); int ...
- 新闻网大数据实时分析可视化系统项目——11、MySQL安装
1.修改yum源 鉴于用国外的Yum源,速度比较慢,所以想到将国外的yum源改为国内的Yum源,这里选择使用比较多的阿里云源.具体修改方法可以参考此连接 2.在线安装mysql 通过yum在线mysq ...
- Django:验证码相关问题
http://blog.csdn.net/csapr1987/article/details/7728315 https://zhidao.baidu.com/question/13837387222 ...
- JS原生编写实现留言板功能
实现这个留言板功能比较简单,所以先上效果图: 实现用户留言内容,留言具体时间. <script> window.onload = function(){ var oMessageBox = ...
- Nginx 的优势
Nginx 的优势 在 Java 开发中,Nginx 有着非常广泛的使用,随便举几点: 使用 Nginx 做静态资源服务器:Java 中的资源可以分为动态和静态,动态需要经过 Tomcat 解析之后, ...
- Mixin类的实现
python类的多重继承由于C3算法的原因导致实现时需要提前规划先后顺序才能正常使用. 这会让人在python中使用多重继承时感到十分的麻烦. 而Mixin类则为我们带来了自由的多重继承和插拔式的舒适 ...
- 深度解析标点符号在Report写作中的应用
准确的标点符号和大写字母可以帮助Tutor准确理解report的意思.标点符号的某些方面,例如使用逗号,可以是一种个人风格,在引号中正确的标点符号是至关重要的.在前面的一些文章当中我们也给大家说了re ...
- 了解AOP以及实现方式
AOP是什么? 面向切面编程,把那些与业务无关,却为业务模块所共同调用的逻辑封装成一个可重的模块,即切面 使用"横切"技术,AOP把软件系统分为两个部分:核心关注点和横切关注点.业 ...
- 初级入门 --- 认识 WebGL
WebGL 是什么? WebGL 是一组基于 JavaScript 语言的图形规范,浏览器厂商按照这组规范进行实现,为 Web 开发者提供一套3D图形相关的 API. 这些 API 能够让 Web 开 ...