ごみ箱を読み取るためにいくつかのシェル関数を使用するため、参照system32/shell32.dllが必要です。「参照の追加->COM->Microsoft Shell ControlsandAutomatation」と「参照の追加->参照--->[system32/shell32.dllに直接移動]」を試しました。どちらもshell32参照を参照に追加します。 。しかし、プロパティを見ると、参照のパスは次のようになっていることがわかります: "C:\ Users \ Tim \ Documents \ Visual Studio 2008 \ Projects \ Wing \ FileWing \ obj \ Debug \ Interop.Shell32.dll" ..。。
この\obj\Debug\パスをインストーラーにデプロイしません。では、エンドユーザーのshell32.dllを直接参照するにはどうすればよいですか?方法はありますか?なぜVS2008はこの奇妙なパスを作成するのですか?このパスを変更して、この奇妙なサブフォルダーに入らないようにすることはできますか?
うーん。さて、PInvokeを再訪した後、私はそれを完全には理解していないと確信しています:-/
処理する必要のあるコードを説明しましょう。ごみ箱を掘り起こし、回収したいアイテムを探しています。これを行うために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;
}
}