为了让Shell32工作,我应该在C#应用程序中包含什么内容?
编辑:
我的应用程序无法识别shell32。我应该包含哪些引用或库?我想做的是:
Shell32.Shell shell = new Shell32.Shell();
我收到的错误信息:
错误1:未找到类型或命名空间名称“Shell32”(是否缺少使用指令或程序集引用?)
为了让Shell32工作,我应该在C#应用程序中包含什么内容?
编辑:
我的应用程序无法识别shell32。我应该包含哪些引用或库?我想做的是:
Shell32.Shell shell = new Shell32.Shell();
我收到的错误信息:
错误1:未找到类型或命名空间名称“Shell32”(是否缺少使用指令或程序集引用?)
只需从Windows\System32
文件夹中添加对Shell32.dll
的引用,然后使用它:
Shell32.Shell shell = new Shell32.Shell();
shell.MinimizeAll();
或许这个可以帮助:
添加引用
添加引用
对话框中,点击.COM
选项卡Microsoft Shell Controls and Automation
你的shell32
已准备就绪...
这个解决方案在Windows 8及更高版本下无法编译。为此,可以在这里找到一个解决方法:
using Shell32;
private Shell32.Folder GetShell32Folder(string folderPath)
{
Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
Object shell = Activator.CreateInstance(shellAppType);
return (Shell32.Folder)shellAppType.InvokeMember("NameSpace",
System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folderPath });
}
C:\Windows\System32
目录。shell32.dll
文件,然后按下“确定”按钮。现在您已经拥有适用于使用 Shell32.Shell
的适当参考。
将COM库Microsoft Shell Controls and Automation添加到您的项目中。此外,确保使用Shell32.Shell
的代码在单线程公寓中运行,例如通过向Main
添加[STAThread]
属性。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MusicMuttPrototype
{
public class clsShellFileInfo
{
public Exception errorException;
public enum FileDetailInfo
{
Name = 0,
Year = 15,
Size = 1,
Track_Number = 19,
Type = 2,
Genre = 20,
Date_Modified = 3,
Duration = 27,
Date_Created = 4,
Bit_Rate = 28,
Date_Accessed = 5,
Protected = 23,
Attributes = 6,
Camera_Model = 24,
Status = 7,
Date_Picture_Taken = 25,
Owner = 8,
Dimensions = 26,
Author = 9,
Not_used = 27,
Title = 10,
Not_used_file = 28,
Subject = 11,
//Not_used = 29,
Category = 12,
Company = 30,
Pages = 13,
Description = 31,
Comments = 14,
File_Version = 32,
Copyright = 15,
Product_Name_Chapter = 33,
//Scripting Quicktest Profess11ional Page 63
Artist = 16,
Product_Version = 34,
Album_Title = 17,
Retrieves_the_info_tip_inf = -1
}
public string getFileDetails(string fileFolder, string filePath, FileDetailInfo infotype)
{
string strReturnval = "";
try
{
Shell32.Shell fileshell = new Shell32.Shell();
Shell32.Folder fileshellfolder = fileshell.NameSpace(fileFolder);
Shell32.FolderItem Item = fileshellfolder.ParseName(filePath);
strReturnval = fileshellfolder.GetDetailsOf(Item, (int)infotype);
}
catch (Exception ex)
{
errorException = ex;
}
return strReturnval;
}
}
}
C# .Net 我不完全理解问题,但这对我有效。
[DllImport("Shell32.dll")]
public static extern int ShellExecuteA(int hwnd, string lpOperation, string lpFile, int lpParameters, int lpDirecotry, int nShowCmd);
private void pictureBox1_Click(object sender, EventArgs e)
{
int open;
open = ShellExecuteA(0, "open", "https://google.com", 0, 0, 1);
}