我试图在 Windows 8.1 中实现自定义 ShellExtension。发现了非常好的SharpShell 教程。
[ComVisible(true)]
[COMServerAssociation(AssociationType.AllFiles)]
public class CountExtProvider : SharpContextMenu
{
protected override bool CanShowMenu()
{
// We will always show the menu.
return true;
}
protected override ContextMenuStrip CreateMenu()
{
// Create the menu strip.
var menu = new ContextMenuStrip();
// Create a 'count lines' item.
var itemCountLines = new ToolStripMenuItem
{
Text = "Count Lines"
};
// When we click, we'll call the 'CountLines' function.
itemCountLines.Click += (sender, args) => CountLines();
// Add the item to the context menu.
menu.Items.Add(itemCountLines);
// Return the menu.
return menu;
}
private void CountLines()
{
// Builder for the output.
var builder = new StringBuilder();
// Go through each file.
foreach (var filePath in SelectedItemPaths)
{
// Count the lines.
builder.AppendLine(string.Format("{0} - {1} Lines",
Path.GetFileName(filePath), File.ReadAllLines(filePath).Length));
}
// Show the ouput.
MessageBox.Show(builder.ToString());
}
}
我在Windows 8.1 RTM x64环境中,所以我在Visual Studio 2013 RC中将构建平台更改为 x64 。添加了一个密钥文件来签署我的 *.dll。但是如果我想注册我的 *.dll 什么都不会发生:
regasm ShellExtensions.dll
命令行显示注册成功,但在上下文菜单中没有条目。我在这里做错了什么?这不再适用于 Windows 8.1 吗?