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

推荐订阅源

U
Unit 42
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
T
Tor Project blog
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
爱范儿
爱范儿
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Vercel News
Vercel News
美团技术团队
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
L
LangChain Blog
IT之家
IT之家
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
Hacker News: Ask HN
Hacker News: Ask HN
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
量子位
Project Zero
Project Zero
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
T
Tenable Blog
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Microsoft Azure Blog
Microsoft Azure Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
Know Your Adversary
Know Your Adversary
L
Lohrmann on Cybersecurity
C
Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
I
InfoQ
P
Privacy & Cybersecurity Law Blog
Spread Privacy
Spread Privacy
Martin Fowler
Martin Fowler
腾讯CDC
S
Security @ Cisco Blogs
F
Fortinet All Blogs

博客园 - 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 返回。