0

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

我将 shell32.dll 添加到我的引用中并尝试编译这个单一的代码行:

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

我得到了一个InvalidCastException

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

我应该如何使用 Shell32.Shell?

4

1 回答 1

2

谢谢,我已经找到了您的评论的方法。我只需要将它用作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

于 2019-01-09T11:19:26.493 回答