Referencing shell32 again, C# Visual Studio

拟墨画扇 提交于 2019-12-05 08:14:26

Right now you're mixing 2 different concepts: PInvoke and COM Interop.

PInvoke allows you to access native C functions from within managed code. It works by defining a marshal compatible signature of the native method in managed code and marking it with the DllImport attribute. It requires, and cannot have, a metadata reference to the native DLL. The DLL is discovered at runtime using normal loading rules for a Win32 DLL.

COM Interop allows you to access COM compatible objects from managed code. This is done by getting a marshal compatible managed definition of the COM interface and then gaining a referece to the object in one of several ways. Getting the managed definition is often accomplished by means of adding a metadata reference to the PIA (primary interop assembly) for the COM component. Until C# 4.0, this reference cannot be removed, without a lot of work, and must be deployed with your application.

In this particular example you are using COM interop and not PInvoke.

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