在 Visual Studio 2010 中制作 Windows shell 扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3670643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making a Windows shell extension in Visual Studio 2010
提问by joshcomley
I'm trying to create an absurdly simple shell extension in C++ using Visual Studio 2010, but I can't even seem to get the examples out there to work as a starting point.
我正在尝试使用 Visual Studio 2010 在 C++ 中创建一个非常简单的 shell 扩展,但我什至无法将示例放在那里作为起点。
I'm using Windows 7 x64.
我正在使用 Windows 7 x64。
I've tried this Visual Studio template, but once I get the template to work in VS2010, I have a host of errors that I'm not sure how to fix.
我已经尝试过这个 Visual Studio 模板,但是一旦我让模板在 VS2010 中工作,我就会遇到许多我不知道如何修复的错误。
I've tried The Complete Idiot's Guide to Writing Shell Extensions, and once the demo compiles all the right registry settings etc. are created but no context menu appears.
我试过The Complete Idiot's Guide to Writing Shell Extensions,一旦演示编译了所有正确的注册表设置等,但没有出现上下文菜单。
I've looked at this C# COM Interop example, but I've been left confused as to whether it is safe to use C# thanks to this article*, but it looks like I might be OK if I use .NET 4 because it supports in process side-by-side CLR hosting.
我看过这个 C# COM Interop 示例,但是由于这篇文章,我对使用 C# 是否安全感到困惑*,但是如果我使用 .NET 4,我似乎可以,因为它支持在进程中并行 CLR 托管。
- in short: historically two versions of .NET cannot run in the same process, and the way shell extensions work is they inject themselves into a process. So if .NET 3.5 gets injected into a .NET 2 process - bang
- 简而言之:历史上两个版本的 .NET 不能在同一个进程中运行,shell 扩展的工作方式是将它们自己注入到一个进程中。因此,如果 .NET 3.5 被注入到 .NET 2 进程中 -砰
So, can I use .NET 4.0 now?
那么,我现在可以使用 .NET 4.0 吗?
Is there a working, downloadable, VS2010 solution that adds a simple shell extension?
是否有可用的、可下载的 VS2010 解决方案,它添加了一个简单的 shell 扩展?
I used to be not so bad with C++ back in the day, but after years of moulding to .NET I'm quite rusty, and as such, fiddling with the details to fix the host of errors I'm getting on the existing examples is proving... fiddly!
过去我对 C++ 的使用还不错,但经过多年的 .NET 成型后,我很生疏,因此,摆弄细节以修复我在现有示例中遇到的大量错误事实证明……很狡猾!
I could really do with a clean slate to start with that I can break myself and figure out what Idid wrong!
我真的可以从头开始,我可以打破自己并找出我做错了什么!
采纳答案by wtjones
I struggled with this for a while and had limited success with the code project article due to x64 issues and SDK differences.
由于 x64 问题和 SDK 差异,我为此苦苦挣扎了一段时间,并且在代码项目文章中取得了有限的成功。
I recently picked the project back up and started over using the MS all-in-onecode sample and I am very pleased. It makes a simple example context menu and x64 works out of the box: http://code.msdn.microsoft.com/windowsdesktop/CppShellExtContextMenuHandl-410a709a
我最近重新选择了该项目并重新开始使用 MS多合一代码示例,我很高兴。它制作了一个简单的上下文菜单示例,并且 x64 开箱即用:http: //code.msdn.microsoft.com/windowsdesktop/CppShellExtContextMenuHandl-410a709a
To get it running on your machine:
让它在你的机器上运行:
- download the code via the all-in-one sample browser or use the direct link.
- Open project in VS under admin rights
- switch build config to x64 and build it
- Kill all explorer sessions
- Locate the new dll and run regsvr32.exe .\CppShellExtContextMenuHandler.dll
- open explorer again and right click a .cpp file to see the new menu
- remove it by running same command with /u flag
- 通过多合一示例浏览器或使用直接链接下载代码。
- 在 VS 中以管理员权限打开项目
- 将构建配置切换到 x64 并构建它
- 杀死所有资源管理器会话
- 找到新的 dll 并运行 regsvr32.exe .\CppShellExtContextMenuHandler.dll
- 再次打开资源管理器并右键单击 .cpp 文件以查看新菜单
- 通过使用 /u 标志运行相同的命令来删除它
My next step is to get debugging working and I think this may do the trick: msdn
我的下一步是让调试工作,我认为这可能会奏效:msdn
回答by patthoyts
On Windows 7 x64 for a C++ extension you need to build it as an x64 project. In Visual Studio 2010 there is an option on the ATL Wizard to create a shell extension project that provides preview window support, thumbnails and Windows Search support. I recently used this and once built, nothing seemed to happen. However, switching the project configuration to build an x64 dll got it working.
在用于 C++ 扩展的 Windows 7 x64 上,您需要将其构建为 x64 项目。在 Visual Studio 2010 中,ATL 向导中有一个选项可以创建外壳扩展项目,该项目提供预览窗口支持、缩略图和 Windows 搜索支持。我最近使用了这个,一旦建成,似乎什么也没发生。但是,切换项目配置以构建 x64 dll 使其正常工作。
With regards to using .Net - Explorer now launches plugins in a separate sub-process. So loading a shell extension that links to .net 4.0 does not contaminate everything with that version of .net as only the hosting subprocess will actually load that CLR. You can see this using a preview extension as a new process (prevhost) gets launched to contain this.
关于使用 .Net - Explorer 现在在单独的子进程中启动插件。因此,加载链接到 .net 4.0 的 shell 扩展不会污染 .net 版本的所有内容,因为只有托管子进程才会实际加载该 CLR。您可以使用预览扩展看到这一点,因为启动了一个新进程(prevhost)来包含它。
回答by Rok Strni?a
I got this one working: http://www.codeproject.com/Articles/174369/How-to-Write-Windows-Shell-Extension-with-NET-Lang
我让这个工作:http: //www.codeproject.com/Articles/174369/How-to-Write-Windows-Shell-Extension-with-NET-Lang
Make sure you use the right RegAsm.exe
for de/registering it:
确保您使用权利RegAsm.exe
取消/注册它:
- 32-bit platforms: Compile for x86/Any CPU. Use
C:\Windows\Microsoft.NET\Framework\vXYZ\RegAsm.exe
. - 64-bit platforms: Compile for x64/Any CPU. Use
C:\Windows\Microsoft.NET\Framework64\vXYZ\RegAsm.exe
.
- 32 位平台:为 x86/任何 CPU 编译。使用
C:\Windows\Microsoft.NET\Framework\vXYZ\RegAsm.exe
. - 64 位平台:为 x64/任何 CPU 编译。使用
C:\Windows\Microsoft.NET\Framework64\vXYZ\RegAsm.exe
.
(XYZ
is the version of the .NET Framework you used for compiling.)
(XYZ
是用于编译的 .NET Framework 版本。)
Note, however, that Microsoft recommends against using .NET for shell extensions.
但是请注意,Microsoft 建议不要将 .NET 用于外壳扩展。
回答by user8268055
The short answer to your 'can I use C#' is no. This is from Microsoft's Guidance for Implementing In-Process Extensions. "One runtime of particular note is the common language runtime (CLR), also known as managed code or the .NET Framework. Microsoft recommends against writing managed in-process extensions to Windows Explorer or Windows Internet Explorer and does not consider them a supported scenario." The problem arises because only a single version of .NET can be used in an application and there is no way to enforce that limitation if multiple .NET extensions are in use.
对“我可以使用 C# 吗”的简短回答是否定的。这是来自 Microsoft 的实现进程内扩展的指南。“一个特别值得注意的运行时是公共语言运行时 (CLR),也称为托管代码或 .NET Framework。Microsoft 建议不要将托管进程内扩展写入 Windows 资源管理器或 Windows Internet Explorer,并且不认为它们是受支持的方案.” 出现问题是因为在应用程序中只能使用单个版本的 .NET,如果使用多个 .NET 扩展,则无法强制实施该限制。