C#Visual Studio 2008的参考system32.dll ......怎么样?
题
我所需要的参考SYSTEM32 / SHELL32.DLL如我使用一些壳函数来读出的回收箱。我试图“添加引用 - > COM - >微软壳牌控制和Automatation”和“添加引用 - >浏览 - > [去到system32 / shell32.dll中直接]无论添加SHELL32参考我引用。但是当我看看属性,我看到了参考看起来像这样的路径:“C:\用户\添\文档\ Visual Studio的2008 \项目\翼\ FileWing \ OBJ \调试\ Interop.Shell32.dll” ...
我不会部署此\ OBJ \调试\我的安装路径。所以,我怎么可以参考终端用户直接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;
}
}
解决方案
我相信你正在寻找的P / Invoke(平台调用)一>
一旦你得到了,包括和使用的DLL下来的方法,您可以访问 pinvoke.net 以获得特定的代码段使用的某些方法。
其他提示
您只需使用 DllImport
来访问功能在SHELL32 / KERNEL32?如果是这样,你不需要添加引用。
例如:
[DllImport("KERNEL32.DLL", EntryPoint="MoveFileW", SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern bool MoveFile(String src, String dst);
下面是关于使用平台调用一个教程>和这里的一个MSDN 文章。
在添加使用VS 2008的DLL参考,可以打开用于该.dll的属性。
确认复制本地设置为True。
如果不工作的另一个解决方案是将.dll添加作为您的项目中的项目,使作为内容,并告诉它复制到输出目录。