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?

1
  • Not sure if it matters, but Shell32.dll should be shell32.dll (Lowercase) Also might want to look at: stackoverflow.com/a/2024978/1218281 Commented Apr 20, 2014 at 13:01

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is what I need to do: codeproject.com/Articles/146757/… 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.
1

I had the same problem and just solved it.

Add the following to your referenced Assemblies list:

    ReferencedAssemblies.Add("Interop.Shell32.dll");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.