简体   繁体   中英

The difference between using extern with dllImport and adding a reference to a project

I have read about extern in MSDN:

http://msdn.microsoft.com/en-us/library/e59b22c5.aspx

I'm not sure what is the difference between using extern than just adding the dll as a reference to the project.

As it is stated it is typically used with DllImport . A common scenario with DllImport is using native dlls instead of managed ones.

As you cannot add native dlls to your project as a reference you need to import it during runtime.

If you have managed assemblies it is typically better to indeed reference it in your project.

See the samples of your link, they import native libraries and call functions on them.

一个区别:如果你想复制或重复使用这段代码,DllImport可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM