CodeMonkey
CodeMonkey

Reputation: 12424

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.

Upvotes: 1

Views: 832

Answers (2)

Mohammad Shokouhi Gol
Mohammad Shokouhi Gol

Reputation: 399

One difference: if you want t copy or reuse of this code, DllImport work fine.

Upvotes: 0

Samuel
Samuel

Reputation: 6490

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.

Upvotes: 4

Related Questions