C# - new Shell32() 引发异常?

C# - new Shell32() throw an exception?

我需要在我的 C# 应用程序中使用 Shell32 来创建一个 lnk 文件。

我将 shell32.dll 添加到我的参考文献中并尝试编译这一行代码:

Shell32.Shell shell = new Shell32.Shell();

我得到了 InvalidCastException

错误代码:'HRESULT: 0x80004002 (E_NOINTERFACE)).'

我应该如何使用Shell32.Shell?

谢谢您,我找到了您的意见。 我只需要将其用作 dynamic.

static readonly Guid CLSID_Shell = Guid.Parse("13709620-C279-11CE-A49E-444553540000");
dynamic shell = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_Shell));

此外,如果我将 STAThreadAttribute 添加到我的 Main 方法中,它可以正常工作(致谢 @Matthew Watson