C # Visual Studio 2008 Link to system32.dll ... how?

I need the reference system 32 / shell32.dll, since I use some shell functions to read the recycle bin. I tried โ€œAdd Link โ†’ COM โ†’ Microsoft Shell Controls and Automatationโ€ and โ€œAdd Link โ†’ Browse ---> [directly in system32 / shell32.dll]. Both add a link to shell32 to my links But when I look at the properties, I I see that the link path looks like this: "C: \ Users \ Tim \ Documents \ Visual Studio 2008 \ Projects \ Wing \ FileWing \ obj \ Debug \ Interop.Shell32.dll" ...

I will not deploy this path \ obj \ Debug \ to my installer. So, how can I directly access shell32.dll end users? Is there any way? Why is VS2008 creating this weird path? Can I change this path so that it does not sit in this strange subfolder?




Hmmm. Well, after re-looking at PInvoke, I'm sure I didn't quite understand: - /

Let me illustrate the code I need to process. I dig in the basket and look for the item that I want to restore. Is there any way to NOT fight though PInvoke to do this?

private void recoverRecyclerBinEntry(string fileName, int size) { try { Shell Shl = new Shell(); Folder Recycler = Shl.NameSpace(10); // scans through all the recyclers entries till the one to recover has been found for (int i = 0; i < Recycler.Items().Count; i++) { FolderItem FI = Recycler.Items().Item(i); string FileName = Recycler.GetDetailsOf(FI, 0); if (Path.GetExtension(FileName) == "") FileName += Path.GetExtension(FI.Path); //Necessary for systems with hidden file extensions. string FilePath = Recycler.GetDetailsOf(FI, 1); string combinedPath = Path.Combine(FilePath, FileName); if (size == FI.Size && fileName == combinedPath) { Debug.Write("Match found. Restoring " + combinedPath + "..."); Undelete(FI); Debug.WriteLine("done."); } else { Debug.WriteLine("No match"); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } private bool Undelete(FolderItem Item) { try { foreach (FolderItemVerb FIVerb in Item.Verbs()) { if ( (FIVerb.Name.ToUpper().Contains("WIEDERHERSTELLEN")) || (FIVerb.Name.ToUpper().Contains("ESTORE")) || (FIVerb.Name.ToUpper().Contains("NDELETE")) ) { FIVerb.DoIt(); return true; } } //execute the first one: Item.Verbs().Item(0).DoIt(); return true; } catch (Exception) { Debug.WriteLine("ERROR undeleting"); return false; } } 
+3
c # shell32
Jan 25
source share
3 answers

I believe you are looking for P / Invoke (Invoke Platform)

Once you get the method for including and using DLL files, you can visit pinvoke.net to get specific pieces of code to use certain methods.

+5
Jan 25 '10 at 15:40
source share

Are you using DllImport to access functions in shell32 / kernel32? If so, you do not need to add a link.

For example:

 [DllImport("KERNEL32.DLL", EntryPoint="MoveFileW", SetLastError=true, CharSet=CharSet.Unicode, ExactSpelling=true, CallingConvention=CallingConvention.StdCall)] public static extern bool MoveFile(String src, String dst); 

Here is a tutorial on using the invoke platform and here is the MSDN article .

+2
Jan 25 '10 at 15:41
source share

After adding the dll link using VS 2008, you can open the properties for the .dll.

Verify that Copy Local is set to True.

If this does not work, another solution is to add the DLL as an element to your project, and make as the content and scan to copy to the output directory.

0
Jan 25 '10 at 15:41
source share



All Articles