Delphi编写DLL供C#调用的实例
Delphi中编写的Dll:
library TestDLL; { Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. } uses
SysUtils,
Classes;
function ADD(X,Y:Integer):Integer;stdcall;
begin
Result :=X+Y;
end;
function Txx(x,y:Double):Double ;stdcall ;
begin
Result :=x+y+y+x;
end;
function EncryVncPassStrHex(Str: PChar): PChar;stdcall; var
TempResult: String;
begin
TempResult := WideCharToString(str);
Result := PChar(TempResult);
end;
{$R *.res}
exports
ADD,
EncryVncPassStrHex,
Txx;
begin
end.
其中涉及到三个输出函数:一个输出的变量为整数,一个为浮点数,另一个为字符串。
C#中调用该Dll:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices; namespace UseDLL
{
/// <summary>
/// Description of MainForm.
/// </summary>
public class UseDLL
{
[DllImport("TestDLL.DLL",EntryPoint="ADD",CharSet= CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
public static extern int add(int x,int y);
[DllImport("TestDLL.DLL",EntryPoint="Txx",CharSet= CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
public static extern double PP(double x,double y);
[DllImport("TestDLL.DLL", EntryPoint="EncryVncPassStrHex",CharSet=CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern string EncryVncPassStrHex( string Str);
} public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent(); //
// TODO: Add constructor code after the InitializeComponent() call.
//
} void Button1Click(object sender, EventArgs e)
{
int x=;
int y=;
int z=UseDLL.add(x,y);
this.textBox1.Text=z.ToString();
double oo=0.123;
double pp=0.254;
this.button1.Text=UseDLL.PP(oo,pp).ToString();
this.Text =UseDLL.EncryVncPassStrHex("我是XXX");
}
}
}
注意:在C#的using部分必须添加“using System.Runtime.InteropServices”。
程序运行结果为:
本程序在delphi2010和SharpDevelop通过。
Delphi编写DLL供C#调用的实例的更多相关文章
- delphi编写dll心得, 谢谢原作者的分享。转
delphi编写dll心得 1.每个函数体(包括exports和非exports函数)后面加 'stdcall;', 以编写出通用的dll2.exports函数后面必须加'export;'(放在'st ...
- Go 程序编译成 DLL 供 C# 调用。
Go 程序编译成 DLL 供 C# 调用. C# 结合 Golang 开发 1. 实现方式与语法形式 基本方式:将 Go 程序编译成 DLL 供 C# 调用. 1.1 Go代码 注意:代码中 ex ...
- 用IKVMC将jar转成dll供c#调用
用IKVMC将jar转成dll供c#调用 ikvmc c# dll jar 用IKVMC将jar转成dll供c#调用 前言 ikvmc介绍 ikvmc下载安装 下载并解压 设置环境变量 jar-> ...
- 分享一次C#调用Delphi编写Dll程序
1.前言: 最近接手了一个项目需要和Delphi语言编写的一个系统进行一些接口的对接,数据在传输过程中采用Des加密方式,因为Delphi 平台的加密方式和C#平台的加密方式不互通,所以采用的方式是C ...
- Delphi 编写DLL动态链接库文件的知识
一.DLL动态链接库文件的知识简介: Windows的发展要求允许同时运行的几个程序共享一组函数的单一拷贝.动态链接库就是在这种情况下出现的.动态链接库不用重复编译或链接,一旦装入内存,Dlls函数可 ...
- Delphi 编写DLL动态链接库文件的知识和样例(有详细步骤,很清楚)
一.DLL动态链接库文件的知识简介: Windows的发展要求允许同时运行的几个程序共享一组函数的单一拷贝.动态链接库就是在这种情况下出现的.动态链接库不用重复编译或链接,一旦装入内存,Dlls函数可 ...
- QT编写DLL给外部程序调用,提供VC/C#/C调用示例(含事件)
最近这阵子,接了个私活,封装一个开发包俗称的SDK给客户调用,查阅了很多人家的SDK,绝大部分用VC编写,而且VC6.0居多,估计也是为了兼容大量的XP用户及IE浏览器,XP自带了VC6.0运行库,所 ...
- delphi 创建DLL文件 及其调用和注意事项
首先创建一个DLL文件,项目自带的代码为: library ProjectPnr; { Important note about DLL memory management: ShareMem mus ...
- [笔记]Delphi 2007写DLL供VC调用实例
考虑如下几种常用情况: - VC传入int,返回int- VC传入char *,返回int- VC传入char *,返回char *及int 为简化问题,传递的字符串参数只考虑ANSI格式,不考虑UN ...
随机推荐
- 1月11日,HTML学习笔记
<ul> <li>coffee</li> <li>tea</li> <li>mile</li> </ul> ...
- [BZOJ 3682]Phorni
后缀平衡树的模板题? I'm so weak…… 现在觉得替罪羊树比 treap 好写,是不是没救了喵- #include <cstdio> #include <cmath> ...
- DataTable 批量插入SqlServer数据库 使用:SqlBulkCopy
简单使用: private void UpdateTitle(DataTable dt) { ) { using (SqlBulkCopy sbc = new SqlBulkCopy(SqlHelpe ...
- Unity进阶技巧 - 动态创建UGUI
前言 项目中有功能需要在代码中动态创建UGUI对象,但是在网上搜索了很久都没有找到类似的教程,最后终于在官方文档中找到了方法,趁着记忆犹新,写下动态创建UGUI的方法,供需要的朋友参考 你将学到什么? ...
- golang下的grpc
facebook的thrift也是开源rpc库,性能高出grpc一倍以上,grpc发展的较晚,期待以后有长足的进步.简单来说thrift = grpc + protobuf gRPC基于HTTP/2标 ...
- js实现页面局部弹窗打印
原文出自:http://www.haorooms.com/post/css3media 在网页中经常看到有打印功能,点击之后,只针对特定区域进行的打印.网上看了一下,大体上有2中实现方法,一种是用cs ...
- HTMLParser使用
htmlparser[1] 是一个纯的java写的html(标准通用标记语言下的一个应用)解析的库,它不依赖于其它的java库文件,主要用于改造或提取html.它能超高速解析html,而且不会出错.现 ...
- 【SharePoint学习笔记】第2章 SharePoint Windows PowerShell 指南
快速了解Windows PowerShell 从SharePoint 2010开始支持PowerShell,仍支持stsadm.exe工具: 可以调用.NET对象.COM对象.exe文 ...
- EL总结
El: 1.el表达式语言(是什么) 2.el是书写到jsp页面 3.el语法格式${ } 4.el算数运算(+,-,*,/,%), 逻辑运算(&&,||,!), 关系运算(>, ...
- oracle 11g dbf数据文件从C盘迁移到D盘
服务器系统为 windows 2008 R2 64位,由于C盘空间将满,要将C盘的oracle的DBF数据文件迁移到D盘下,步骤如下: 1.输入cmd,启动 cmd.exe窗口 2.输入 sqlplu ...