惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
V
Visual Studio Blog
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
B
Blog
I
InfoQ
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
H
Help Net Security
博客园 - Franky
宝玉的分享
宝玉的分享
博客园 - 司徒正美
C
Check Point Blog
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家

博客园 - KeithDan

Windows 8开发 WinRT 对ZIP文件解压缩及文件夹的ZIP压缩 wp应用发布,金宝贝点读 WP7游戏分裂细胞 WP7游戏方块夺宝 C#手工解析XML xeno tactic 2 完整版 Lua扫雷 惊人!天下奇闻“鹏” 今天很郁闷 HighLightCode1.2——开源项目 代码着色--关于循环与分组 代码着色--开源系列 利用非托管dll实现多平台加密 page_load执行两次 transfer object (3) transfer object (2) transfer object (1) 中国象棋(网络版) 人生的阶梯
非托管dll的需要注意的地方
KeithDan · 2007-11-30 · via 博客园 - KeithDan

作为不同的平台应用,经常会有非托管的dll文件需要调用.
在这里需要注意的两个地方,在这里我只说delphi编写的文件.非托管dll被C#调用首先是数据类型的问题,在delphi里面如果需要被其他程序语言调用,作为参数或者返回值的字符不能使用string类型,而是pchar.而对于recode,则对应是struct
比如,在delphi里面函数原形

function A():pchar;export; stdcall;


c#调用

[DllImport(@"xxx.dll")]
public static extern string A();


delphi

type TypeA=packed record
a1:pChar;
a2:pChar;
end;

function B(A:TypeA):boolean;export; stdcall;

c#

public TypeARsaKey
{
            
public string a1;
            
public string a2;
        }

[DllImport(
@"xxx.dll")]
        
public static extern bool B(TypeA A);

第二个问题是如果我们需要返回recode,那么我们不能使用函数返回模式,而应该使用var形式
delphi:

type TypeA=packed record
a1:pChar;
a2:pChar;
end;

function B(var A:TypeA):boolean;export; stdcall;

c#

public TypeARsaKey
{
            
public string a1;
            
public string a2;
        }

[DllImport(
@"xxx.dll")]
        
public static extern bool B(ref TypeA A);