DllImport vs LoadLibrary, What is the best way?

可紊 提交于 2019-12-01 22:42:17

Most of the Win32 API is available through managed abstractions. Otherwise, declare the ones you need using DllImport.

LoadLibrary should really only be used where you have provided alternate functionality, that is, your application can work even without that particular API function. If the API function is critical, using DllImport will let the loader worry about whether the function exists or not.

LoadLibrary is useful when you are writing code that might be used in an environment that may or may not have the desired dll -- for example, you might have a program that can use a special crypto dll if it is available, but can still operate without it. Using DllImport would require that dll to exist.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!