C#Visual Studio 2008的参考system32.dll ...怎么样?Studio、Visual、dll

2023-09-05 02:32:02 作者:雨落倾城〆夜微凉〞

我需要参考SYSTEM32 / shell32.dll中,我使用一些shell函数读出回收站。我试图添​​加引用 - > COM - >微软壳牌控制和Automatation和添加引用 - >浏览 - > [去到system32 / SHELL32.DLL直接]无论加SHELL32提及我引用但是当我在看属性,我看到了参考的路径是这样的:C:\用户\添\文档\ Visual Studio 2008的\项目\荣\ FileWing \ OBJ \调试\ Interop.Shell32.dll ......

我不会部署此\ OBJ \调试\路径,我的安装程序。所以,我怎么能直接引用最终用户使用shell32.dll?有什么办法?为什么VS2008建立这种奇怪的路径?我可以改变这个路径,因此它不会在这个陌生的子文件夹坐?

嗯。好了重新审视的PInvoke后,我敢肯定,我不太明白: - /

让我来举例说明了code我需要处理。我挖,虽然回收站,并寻求,我想要恢复的项目。有什么办法不战虽然的PInvoke来完成这件事?

 私人无效recoverRecyclerBinEntry(字符串文件名,诠释大小)
    {
        尝试
        {
            壳牌SHL =新的shell();
            夹回收站= Shl.NameSpace(10);

            通过所有回收项目,直到一个恢复//扫描已被发现
            的for(int i = 0; I< Recycler.Items()计数;我++)
            {
                的FolderItem FI = Recycler.Items()(i)项。
                字符串文件名= Recycler.GetDetailsOf(FI,0);
                如果(Path.GetExtension(文件名)==)
                    文件名+ = Path.GetExtension(FI.Path);
                //必要时作隐藏文件扩展名的系统。

                串FILEPATH = Recycler.GetDetailsOf(FI,1);
                字符串combinedPath = Path.Combine(文件路径,文件名);

                如果(大小== FI.Size和放大器;&安培;文件名== combinedPath)
                {
                    Debug.Write(比赛中恢复。+ combinedPath +...);
                    取消删除(FI);
                    的Debug.WriteLine(完成的。);
                }
                其他
                {
                    的Debug.WriteLine(不匹配);
                }
            }
        }
        赶上(例外前)
        {
            的Debug.WriteLine(ex.Message);
            的Debug.WriteLine(ex.StackTrace);
        }
    }

    私人布尔取消删除(项目的FolderItem)
    {
        尝试
        {
            的foreach(FolderItemVerb FIVerb在Item.Verbs())
            {
                如果 (
                    (FIVerb.Name.ToUpper()。包含(WIEDERHERSTELLEN))||
                    (FIVerb.Name.ToUpper()。包含(ESTORE))||
                    (FIVerb.Name.ToUpper()。包含(n删除))
                    )
                {
                    FIVerb.DoIt();
                    返回true;
                }
            }
            //执行第一个:
            。Item.Verbs()项目(0).DoIt();
            返回true;
        }
        赶上(例外)
        {
            的Debug.WriteLine(错误取消删除);
            返回false;
        }
    }
 

解决方案

我相信你正在寻找的的P / Invoke(平台调用)

一旦你的方法,包括使用的DLL文件时,您可访问 pinvoke.net 获得具体code段使用某些方法。

Microsoft Visual C 2008专业绿色版下载 快猴软件下载

I need the reference system32/shell32.dll as I use some shell functions to read out the recycling bin. I tried "Add Reference --> COM --> Microsoft Shell Controls and Automatation" and "Add Reference --> Browse ---> [going to the system32/shell32.dll directly]. Both adds the shell32 reference to my references. But when I look at the properties, I see the path of the reference looks like this: "C:\Users\Tim\Documents\Visual Studio 2008\Projects\Wing\FileWing\obj\Debug\Interop.Shell32.dll" ...

I'll not deploy this \obj\Debug\ path to my installer. So how can I reference the end-users shell32.dll directly? Is there a way? Why does VS2008 create this strange path? Can I change this path so it doesn't sit in this strange subfolder?

Hmmm. Okay after revisiting PInvoke, I'm sure that I don't quite get it :-/

Let me illustrate the code I need to handle. I'm digging though the recycling bin and seek for a item that I want to recover. Is there any way NOT fighting though the PInvoke to get this done?

    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;
        }
    }

解决方案

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

Once you get the method for including and using the DLLs down, you can visit pinvoke.net to get specific code snippets for using certain methods.