0

我需要在我的程序中使用 shell32 来创建快捷方式。

这是我的代码:

var compiler = new CSharpCodeProvider();
var Params = new System.CodeDom.Compiler.CompilerParameters
{
      GenerateExecutable = true,
      OutputAssembly = outputName,
      ReferencedAssemblies = {
                    "System.dll",
                    "System.Core.dll",
                    "System.Windows.Forms.dll",
                    "System.Drawing.dll",
                    @"C:\Windows\System32\Shell32.dll"
 }
};

这样做,我得到一个错误:

元数据文件 C:\Windows\System32\Shell32.dll 无法打开。试图加载格式不正确的程序。

搜索时什么也没找到..我什至不确定要搜索什么:/

我该怎么做呢?

4

2 回答 2

2

Shell32.dll(Windows 文件系统不关心大小写,因此“s”或“S”无关紧要)不是 .NET 程序集,因此不能这样对待。

如果要调用从非 .NET 库导出的函数,则应使用DllImportAttribute.

于 2014-04-20T13:09:37.350 回答
1

我有同样的问题,刚刚解决了。

将以下内容添加到您引用的程序集列表中:

    ReferencedAssemblies.Add("Interop.Shell32.dll");
于 2015-08-20T02:12:11.570 回答