delphi dll 源码:

library dllres;

  type
char10 = array[..] of char;
TMydata = packed record
id: Integer;
name: char10;
married: Boolean;
salary: Double;
end;
PMydata = ^TMydata; const
RESSTR: array[..] of string = ('HELLO', 'COLOR', 'DELPHI', 'shared', 'library');
NO_RESULT= 'no result';
var
mydata: TMydata; {$R *.res}
// 返回字符串指针
function getResStr(aindex: Integer): PChar; stdcall;
begin
if aindex < Length(RESSTR) then
begin
Result := pchar(RESSTR[aindex]);
end
else
begin
Result := pchar(NO_RESULT);
end;
end; // 返回结构体指针
function getMydata: PMydata; stdcall;
begin
with mydata do
begin
id := ;
name := 'obama';
married := false;
salary := ;
end;
Result := @mydata;
end; exports getResStr, getMydata; begin
end.

C# 调用示例:

    class Invoke_Delphi_Dll_Exam
{
[DllImport("dllres.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr getResStr(int index); [DllImport("dllres.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr getMydata(); public struct Mydata
{
public int id; //
public string name; //
public bool married; //
public double salary; // public Mydata(byte[] data)
{
if (data != null && data.Length == ) {
id = BitConverter.ToInt32(data, );
name = Encoding.Unicode.GetString(data, , ).Replace("\0",""); // 去掉尾部的0字符
married = BitConverter.ToBoolean(data, );
salary = BitConverter.ToDouble(data, );
}
else {
id = ;
name = String.Empty;
married = false;
salary = ;
}
} public override string ToString()
{
return String.Format("id: {0}, name: {1}, married: {2}, salary: {3}",
id, name, married, salary);
}
} private static void Main(string[] args)
{
Console.WriteLine(Marshal.PtrToStringAuto(getResStr())); byte[] data = new byte[];
Marshal.Copy(getMydata(), data, , );
Mydata mydata = new Mydata(data);
Console.WriteLine(mydata);
}
}

C# 调用Delphi dll的更多相关文章

  1. 在.net中调用Delphi dll的Pchar转换

    Pchar是非托管代码,要在.net中调用Delphi dll中的功能,请使用MarshalAs属性告知.net调用PInvoke去转换.net中标准的string类型.如果Delphi dll是De ...

  2. vb6如何调用delphi DLL中的函数并返回字符串?

    1,问题描述 最近发现vb6调用delphi DLL中的函数并返回字符串时出现问题,有时正常,有时出现?号,有时干脆导致VB程序退出 -- :: 将金额数字转化为可读的语音文字:1转化为1元 ???? ...

  3. Visual Studio 调用 Delphi DLL 会退出的解决方案

    新写了一个 Delphi 的 dll 供 C# 程序调用,却发现在使用 Visual Studio 2012 进行调试时,程序会在调用后自动退出. 经过对比,只需要将工程属性中“调试”一页下的“启用 ...

  4. C#调用Delphi DLL获取字符串(C# IntPtr 与 string互转 )

    前因后果 调用一门锁的dll实现读取酒店IC卡数据,直接用Readme里的方法出错. 函数声明: 一.读卡函数    ************************ Delphi 调用 ****** ...

  5. VC调用Delphi DLL

    别的没什么,是一定可以调用成功的.但是意外的是,ShowMessage函数在DLL里也可以轻易被调用.此外,Delphi里的var 相当于VC里的引用,需要在函数原型里正确标识,否则传递普通变量甚至常 ...

  6. C#调用Delphi Dll返回字符串的示例(使用Move才能拷贝字符串)

    //----------------------Delphi------------------- procedure GetSqlData(ASource: PChar; ADest: PChar; ...

  7. Delphi DLL的创建、静态及动态调用

    转载:http://blog.csdn.net/welcome000yy/article/details/7905463 结合这篇博客:http://www.cnblogs.com/xumenger/ ...

  8. VS2017写的exe调用Delphi 7写的DLL

    公司有个很古老的系统,代码量很大,并且稳定线上运行10几年,这系统是公司的核心,公司收入基本靠它,系统几乎都是Delphi 7写的,要重写是不可能的.因为Delphi 7编译出来的DLL默认的导出符号 ...

  9. C#调用Delphi的dll之详解

    C#调用Delphi接口方法,有两种解决办法: 一.将Delphi程序编译成一个COM组件,然后在C#里引用COM组件. 二.非托管调用Dephi的DLL文件. 这里我们主要讲解一下第二种方法,讲第二 ...

随机推荐

  1. 各种装饰器demo及优化

    #!/usr/bin/python3# -*- coding: utf-8 -*-# @Time    : 2018/5/28 14:06# @File    : lianxi.py ## impor ...

  2. OpenCV Hello World

    ▶ OpenCV 的环境配置与第一个程序 ● 去官网下载安装包 https://opencv.org/releases.html ▶ OpenCL 在Visual Studio 2015 中的配置.注 ...

  3. Python实践练习:选择性拷贝

    题目 项目要求:编写一个程序,遍历一个目录树,查找特定扩展名的文件(诸如.pdf 或.jpg),不论这些文件的位置在哪里, 将它们拷贝到一个新的文件夹中. 代码 import os import sh ...

  4. Delphi7 [Fatal Error] ClassPas.pas(8): File not found: 'DesignIntf.dcu'

    Delphi7 [Fatal Error] ClassPas.pas(8): File not found: 'DesignIntf.dcu' Add path to Project>Optio ...

  5. LUA表与函数的深入理解

    local heroInfo = {} --直接打印 table的名字,就会输出该table的内存地址 print("表地址---------------",heroInfo) - ...

  6. 【Git】三、工作区、暂存区、版本库

    一.基础概念 工作区:电脑中可以看到的目录,为电脑中的项目文件 暂存区:暂存修改的地方 版本库:存放项目的各个版本文件 二.详细介绍 工作区为我们工作所使用的目录,在工作区我们对项目文件进行增删改查. ...

  7. zabbix监控阅读目录

    一.zabbix安装 点击查看:http://www.cnblogs.com/hwlong/p/5820321.html 二.解决乱码问题 点击查看:http://www.cnblogs.com/hw ...

  8. sql产生随机数字

    第一种:select cast(ceiling(rand() * 10) as int)第二种:select cast(ceiling(rand(checksum(newid()))*10) as i ...

  9. Python之Scrapy遇见个坑

    运行Scrapy爬虫被限制抓取,报错: -- :: [scrapy.middleware] INFO: Enabled item pipelines: [] -- :: [scrapy.core.en ...

  10. Java 设计模式系列(八)装饰者模式

    Java 设计模式系列(八)装饰者模式 装饰模式又名包装(Wrapper)模式.装饰模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替代方案.Decorator 或 Wrapper 一.装饰模 ...