0

I need shell32 in my program to create a shortcut.

This is my code:

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"
 }
};

Doing this, I get an error:

Metadata file C:\Windows\System32\Shell32.dll could not be opened. An attempt was made to load a program with incorrect format.

Found nothing while searching.. I wasn't even sure what to search for :/

How would I go about doing this?

Raging Bull
  • 18,593
  • 13
  • 50
  • 55
Andreas
  • 558
  • 6
  • 5
  • Not sure if it matters, but `Shell32.dll` should be `shell32.dll` (Lowercase) Also might want to look at: http://stackoverflow.com/a/2024978/1218281 – Cyral Apr 20 '14 at 13:01

2 Answers2

2

Shell32.dll (Windows file systems don't care about case, so "s" or "S" shouldn't matter) is not a .NET assembly and thus can't be treated as such.

If you want to call functions exported from non-.NET libraries, you should use the DllImportAttribute.

Wormbo
  • 4,978
  • 2
  • 21
  • 41
  • This is what I need to do: http://www.codeproject.com/Articles/146757/Add-Remove-Startup-Folder-Shortcut-to-Your-App However, I can't add references like it is shown there. I need to do it programatically. I don't understand how I'd go about using DllImport. – Andreas Apr 20 '14 at 13:19
1

I had the same problem and just solved it.

Add the following to your referenced Assemblies list:

    ReferencedAssemblies.Add("Interop.Shell32.dll");
mrAtari
  • 620
  • 5
  • 17