Pregunta

I necesita la referencia system32 / shell32.dll como yo uso algunas funciones de shell para leer la papelera de reciclaje. Probé "Agregar referencia -> COM -> Controles de Microsoft Shell y Automatation" y "Agregar referencia -> Navegar ---> [ir al system32 / shell32.dll directamente] Tanto añade la referencia shell32 a mis referencias. . Pero cuando miro a las propiedades, veo el camino de las miradas referencia así: "C: \ Users \ Tim \ Documents \ Visual Studio 2008 \ Projects \ ala \ FileWing \ obj \ Debug \ Interop.Shell32.dll" ...

No va a implementar esta \ obj \ Debug \ ruta al instalador. Entonces, ¿cómo puedo hacer referencia a que los usuarios finales SHELL32.DLL directamente? ¿Hay alguna manera? ¿Por qué VS2008 crear este extraño camino? ¿Puedo cambiar esta ruta para que no se sienta extraño en esta subcarpeta?


Hmmm. Bien después de volver a visitar PInvoke, estoy seguro de que yo no lo entiendo muy bien: - /

Vamos a ilustrar el código que necesito para manejar. Estoy cavando aunque la papelera de reciclaje y buscar para un artículo que desea recuperar. ¿Hay alguna manera no luchar aunque el PInvoke para hacer esto?

    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;
        }
    }
¿Fue útil?

Solución

Creo que busca P / Invoke (invocación de plataforma)

Una vez que el método para incluir y utilizar los archivos DLL abajo, se puede visitar pinvoke.net a obtener fragmentos de código específicas para el uso de ciertos métodos.

Otros consejos

¿Usted apenas está utilizando DllImport a la funcionalidad de acceso en shell32 / kernel32? Si es así, no es necesario añadir una referencia.

Por ejemplo:

[DllImport("KERNEL32.DLL", EntryPoint="MoveFileW",  SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern bool MoveFile(String src, String dst);

Aquí hay un tutorial sobre el uso de invocación de plataforma y aquí está una de MSDN artículo .

Después de agregar la referencia DLL utilizando VS 2008, puede abrir las propiedades de la .dll.

Asegúrese de que copia local se establece en True.

Si eso no funciona, otra solución es añadir la .dll como un elemento para proyectar, y hacer que es como el contenido, y decirle que copiar en el directorio de salida.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top