I was wondering what is the very top most declared references and why we still need to use DllImport? I'm talking C#.
The MSDN states: "The DllImport attribute is very useful when reusing existing unmanaged code in a managed application. For instance, your managed application might need to make calls to the unmanaged WIN32 API." But, is that saying it is not useful to reference an unmanaged dll or impossible otherwise?
DllImport Attribute is a declarative tag used in C# to mark a class method as being defined in an external dynamic-link library (DLL) rather than in any . NET assembly.
From the MDSN documentation:
The DllImport attribute is very useful when reusing existing unmanaged code in a managed application. For instance, your managed application might need to make calls to the unmanaged WIN32 API.
Basically, when you're writing a .NET application, and a library does not have a managed wrapper (it's written in unmanaged code), you need to use DllImport to interoperate with it. Otherwise, you can reference managed libraries with a using
statement like you normally would any base class library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With