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

推荐订阅源

博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
宝玉的分享
宝玉的分享
腾讯CDC
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
T
The Blog of Author Tim Ferriss
V
V2EX
S
Securelist
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Y
Y Combinator Blog
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
T
Threat Research - Cisco Blogs
B
Blog
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
H
Help Net Security
C
Cisco Blogs
C
Check Point Blog
S
Secure Thoughts

博客园 - 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);