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

推荐订阅源

Project Zero
Project Zero
Y
Y Combinator Blog
雷峰网
雷峰网
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
博客园 - 聂微东
S
SegmentFault 最新的问题
Engineering at Meta
Engineering at Meta
罗磊的独立博客
M
MIT News - Artificial intelligence
B
Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
大猫的无限游戏
大猫的无限游戏
V
V2EX
I
InfoQ
The Cloudflare Blog
Cloudbric
Cloudbric
Stack Overflow Blog
Stack Overflow Blog
V
Vulnerabilities – Threatpost
博客园_首页
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
T
The Exploit Database - CXSecurity.com
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
美团技术团队
K
Kaspersky official blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tor Project blog
P
Privacy International News Feed
P
Privacy & Cybersecurity Law Blog
G
GRAHAM CLULEY
博客园 - 三生石上(FineUI控件)
Cyberwarzone
Cyberwarzone
Vercel News
Vercel News
Cisco Talos Blog
Cisco Talos Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cisco Blogs
G
Google Developers Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
Arctic Wolf
MongoDB | Blog
MongoDB | Blog

博客园 - Achilles.NET

路过 通过javascript获得当前窗口页面的宽高度 SQL SERVER设置重新构造字段值大小写敏感 - Achilles.NET - 博客园 修改SQL默认不区分大小写字段值规则 [转帖]Transact-SQL编程规范 Version 1.1 C#调用存储过程返回值 - Achilles.NET - 博客园 Ghost备份后找不到gho镜像文件的解决办法 GridView数据突出颜色显示解决办法 GridView中空记录不显示表头的解决方案[作者不祥] Temple js控制标题闪动 山西DOT NET俱乐部 WEB弹出窗口打印 打印脚本 DataGrid分页 妻子让老公死心塌地的绝招 下班无聊,随便YY const(C# 参考) ERP──Enterprise Resource Planning 企业资源计划系统
extern(C# 参考)
Achilles.NET · 2007-03-06 · via 博客园 - Achilles.NET

   extern修饰符用于声明在外部实现的方法。
   extern 修饰符的常见用法是在使用 Interop 服务调入非托管代码时与 DllImport 属性一起使用;在这种情况下,该方法还必须声明为 static,如下面的示例所示:
    [DllImport("avifil32.dll")]
    private static extern void AVIFileInit();

注意 
   extern 关键字还可以定义外部程序集别名,使得可以从单个程序集中引用同一组件的不同版本。
 将 abstract 和 extern 修饰符一起使用来修改同一成员是错误的。

使用 
   extern 修饰符意味着方法在 C# 代码的外部实现,而使用 abstract 修饰符意味着在类中未提供方法实现。注意 extern 关键字在使用上比在 C++ 中有更多的限制。
 
示例 
   在该示例中,程序接收来自用户的字符串并将该字符串显示在消息框中。程序使用从 User32.dll库导入的 MessageBox 方法。
using System; using System.Runtime.InteropServices;
class MainClass
{
 [DllImport("User32.dll")]
 public static extern int MessageBox(int h, string m, string c, int type);
 static int Main()
{
string myString;
 Console.Write("Enter your message: ");
 myString = Console.ReadLine();
return MessageBox(0, myString, "My Message Box", 0);
}
}
 此示例使用 C 程序创建一个 DLL,在下一示例中将从 C# 程序调用该 DLL。
// cmdll.c // compile with:
/LD int __declspec(dllexport) SampleMethod(int i)
{
 return i*10;
 }
该示例使用两个文件 CM.cs 和 Cmdll.c 来说明 extern。
C 文件是示例 2 中创建的外部 DLL,它从C# 程序内调用。
// cm.cs using System;
using System.Runtime.InteropServices;
public class MainClass {
 [DllImport("Cmdll.dll")]
public static extern int SampleMethod(int x);
 static void Main()
 {
Console.WriteLine("SampleMethod() returns {0}.", SampleMethod(5));
}
}
输出SampleMethod() returns 50. 备注生成项目: 使用 Visual C++ 命令行将 Cmdll.c 编译为 DLL: cl /LD Cmdll.c 使用命令行编译 CM.cs: csc CM.cs 这将创建可执行文件 CM.exe。运行此程序时,SampleMethod 将值 5 传递到 DLL 文件,该文件将此值乘以 10 返回。