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 ...
随机推荐
- HDU 5964 平行四边形
假设直线L和L'相交于原点O.假设S ={s1,s2,...,sn}是平面上的n个点.你打 算找四个点满足如下条件:1. A ∈ L 而 A' ∈ L'.2. B,B'都属于S;即 B∈S 且 ...
- 子句jion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- nginx入门篇----负载均衡策略
负载均衡策略 负载均衡策略:内置策略和扩展策略. 内置策略包括:轮询.加权轮询.IP hash:扩展策略包括:url hash.fair等 策略详细介绍 轮询:对前端的访问逐一分流到后端网络节点,类似 ...
- Python isinstance() type()
isinstance(object, classinfo) 判断实例是否是这个类或者object是变量 classinfo 是类型(tuple,dict,int,float,long...)(包括自定 ...
- 转载:详细解析Java中抽象类和接口的区别
在Java语言中, abstract class 和interface 是支持抽象类定义的两种机制.正是由于这两种机制的存在,才赋予了Java强大的 面向对象能力.abstract class和int ...
- Visual studio智能感知挡住了当前代码输入行
AssistX->Listboxes->Enable Visual Assist completion, suggestion and member list in .. 如果勾选了该项就 ...
- Spring Security 3整合CAS 实现SSO
spring security 3整合cas client用于实现各Application之间的单点登录. 1. 需要准备的jar spring-security-core-3.0.8.RELEASE ...
- MSSQL 多行合并为一行
select ptl_a01, ptl_piitem, ( ) as ptl_count, STUFF((SELECT ','+ltrim(ptl_pdid) FROM PRODUCT_TRACEAB ...
- 清除系统日志及数据库(sql server)日志最佳实践
在一个项目中遇到的问题:系统日志过大,后来用delete语句删除了(相当的慢),结果数据库日志又变成很大了(差不多10G),所以又得把数据库日志删除. 方法: --备份系统中的部份日志--SELECT ...
- 关于Failed to install helloworld.apk on device 'emulator-5554!的一个解决办法
好不容易架好了android环境,把该安得都安好了,结果发现在安装过程中创建一个虚拟设备映象就占用了c盘34g的空间,我的系统盘差点瘫了,看来以后就只能先用这一个虚拟设备调试了, 接着说上边这个问题, ...