我需要參考system32/shell32.dll,因爲我使用一些shell函數來讀出回收站。我嘗試了「Add Reference - > COM - > Microsoft Shell Controls and Automatation」和「Add Reference - > Browse ---> [直接進入system32/shell32.dll]。兩者都將shell32引用添加到我的引用。但是當我看看屬性時,我看到引用的路徑如下所示:「C:\ Users \ Tim \ Documents \ Visual Studio 2008 \ Projects \ Wing \ FileWing \ obj \ Debug \ Interop.Shell32.dll」 ...C#Visual Studio 2008引用system32.dll ...如何?
我不會將這個\ obj \ Debug \路徑部署到我的安裝程序,那麼我怎樣才能直接引用最終用戶shell32.dll?有什麼辦法嗎?爲什麼VS2008創建這個奇怪的路徑?我可以改變這個路徑,因此不會在這個陌生的子文件夾坐?
嗯。好了重新審視PI後nvoke,我敢肯定,我不太明白: -/
讓我說明我需要處理的代碼。我正在挖掘回收箱,並尋找我想恢復的物品。有沒有辦法不通過PInvoke來完成這個任務?
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;
}
}
是的,你不添加一個對shell32.dll的引用(至少通過正常的添加引用),你改用P/Invoke。甚至有一個專門的網站,http://www.pinvoke.net/ – 2010-01-25 15:42:15
謝謝,我想是這樣。非常感謝! – Akku 2010-01-25 15:53:46
好吧,我想我正在尋找一些東西 - 比較容易。請在下面寫下其他評論,請重新回顧一下......我非常無奈。 – Akku 2010-01-25 16:11:35