Hmmm. Ok, dopo aver rivisitato PInvoke, sono sicuro di non averlo capito: -/(appena chiesto this question)Fare nuovamente riferimento a shell32, C# Visual Studio
Lasciatemi illustrare il codice che devo gestire. Funziona quando uso "Aggiungi riferimento -> COM -> Microsoft Shell Controls and Automatation" ... ma purtroppo pone un riferimento nel mio progetto che assomiglia a questo: "C: \ Users \ Tim \ Documents \ Visual Studio 2008 \ Projects \ Wing \ FileWing \ obj \ Debug \ Interop.Shell32.dll "
Sto scavando attraverso il cestino e cerco un oggetto che voglio recuperare. C'è un modo per NON combattere attraverso il PInvoke per fare questo? O per ottenere un riferimento al system32/shell32.dll che mi permette di utilizzare questo codice in fase di runtime?
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;
}
}
Prima di tutto - mi dispiace, appena finito l'università e non insegnano winapis ci ;-) Va bene, così io uso l'interoperabilità COM. Dici che ho bisogno di un riferimento all'assemblea di interoperabilità. Immagino che questa roba sia qui, che è piuttosto piccola e va bene per me: .. \ Visual Studio 2008 \ Projects \ Wing \ FileWing \ obj \ Debug \ Interop.Shell32.dll Ora la mia domanda è: come posso influenzare dove viene creato questo oggetto (come impostare il percorso di questo oggetto da qualche altra parte) o come posso distribuire questo oggetto prima, quindi è installato con la mia applicazione? – Akku
@ Tim, non credo che tu possa influenzare dove è stato creato. È fatto automaticamente dal sistema di compilazione. Per distribuirlo è sufficiente copiarlo nella cartella di destinazione dell'applicazione. – JaredPar
Grazie! Questo è esattamente quello che dovevo fare :-) – Akku