简体   繁体   English

使用C#创建Windows-7库

[英]Creating windows-7 library using c#

Windows-7 introduced a concept of virtual folder, called 'Libraries'. Windows-7引入了虚拟文件夹的概念,称为“库”。

I am working on implementing a Library with my custom action. 我正在通过自定义操作实现图书馆。 The constraint is that, I have to stick to .NET version 2 for this :( 约束是,我必须为此坚持使用.NET版本2 :(

While looking around, I didn't find any native (c/C++) API for doing this. 环顾四周时,我没有发现任何可用于此目的的本机(c / C ++)API。 I am planning to use Interop (p-Invoke) to make a library once I get native APIs. 一旦获得本机API,我计划使用Interop(p-Invoke)创建一个库。

Could any one point to a link or documentation which might help. 任何人都可以指向可能会有所帮助的链接或文档。 If somehow I can do this directly from c# (with .NET v2), that would be great. 如果我能以某种方式直接从c#(使用.NET v2)中做到这一点,那就太好了。

Thank you, John 谢谢约翰

The MSDN topics that seem most pertinent are: 看起来最相关的MSDN主题是:

The library features are exposed through COM so there's no need for P/invoke. 库功能通过COM公开,因此不需要P /调用。

However, since libraries only exist in Windows 7, and since Windows 7 has .net 3.5 as part of the OS, I would recommend that you put this part of your application in a .net 3.5 assembly. 但是,由于库仅存在于Windows 7中,并且由于Windows 7将.net 3.5作为操作系统的一部分,因此我建议您将应用程序的这一部分放在.net 3.5程序集中。 In fact the API CodePack assembly already does this for you. 实际上, API CodePack程序集已经为您完成了此任务。

Of course, since the CodePack is also delivered as source you could extract the necessary parts from there and do what is needed in order to build it against .net 2.0. 当然,由于CodePack也作为源代码提供,因此您可以从那里提取必要的部分,并做一些必要的工作以针对.net 2.0构建它。

The concept of "virtual folder" exists already before Windows 7 and has AFAIK just been "refined"... you write you want to do this with your own custom handler... Windows 7之前就已经存在“虚拟文件夹”的概念,并且已经对AFAIK进行了“改进” ...您编写自己的自定义处理程序来执行此操作...

IF you want to implement such a "virtual folder" and integrate it into Windows so that other applications can use it as a "virtual folder" then: 如果要实现这样的“虚拟文件夹”并将其集成到Windows中,以便其他应用程序可以将其用作“虚拟文件夹”,则:

To implement and install a "shell extension" (which basically are a bunch of COM interfaces): 要实现并安装“外壳扩展”(基本上是一堆COM接口):

Remark: If the system you are running on doesn't have .NET 4 then Microsoft recommended NOT to use .NET for this because of the inherent restriction with the older versions that one process can't run multiple framework versions at the same time. 备注:如果运行的系统没有.NET 4,则Microsoft建议不要使用.NET,因为较旧版本存在固有的限制,即一个进程不能同时运行多个框架版本。 Depending on the OS etc. case it could be recommended to implement this with C/C++. 根据操作系统等情况,建议使用C / C ++来实现。
Even with .NET 4 as pointed out in the comments the code injection problem remains - ie if any .NET app prior .NET 4 and/or with a different .NET versions than your shell extension accesses the file open dialog for example it can/will fail. 即使使用注释中指出的.NET 4,代码注入问题仍然存在-即,如果任何.NET 4之前的.NET应用程序和/或具有与Shell扩展不同的.NET版本,则可以访问文件打开对话框,例如,它可以/将失败。
To circumvent that you need to implement a native proxy DLL which gets loaded into the respective processes (like Windows Explorer) and communicates with your .NET implementation via IPC. 为了避免这种情况,您需要实现一个本机代理DLL,该DLL将被加载到相应的进程中(例如Windows资源管理器),并通过IPC与.NET实现进行通信。

In this specific case you need to build a shell extension which implements IShellLibrary . 在这种情况下,您需要构建一个实现IShellLibrary的Shell扩展。

That aside the implementation of shell extension is a really tough job... some links with information / samples / source code / libraries etc.: 除了shell扩展的实现之外,这确实是一项艰巨的工作……与信息/示例/源代码/库等相关的一些链接:

To interact with a Windows 7 library see http://support.microsoft.com/kb/976027 and http://www.codeproject.com/KB/miscctrl/Windows7APICodePack.aspx and http://archive.msdn.microsoft.com/WindowsAPICodePack and http://www.codeproject.com/KB/cs/DDW7LibrariesLite.aspx . 要与Windows 7库进行交互,请参见http://support.microsoft.com/kb/976027http://www.codeproject.com/KB/miscctrl/Windows7APICodePack.aspxhttp://archive.msdn.microsoft。 com / WindowsAPICodePackhttp://www.codeproject.com/KB/cs/DDW7LibrariesLite.aspx Some require .NET 3.5 but since 3.5 is just 2.0 plus some additional assemblies it might be an option... 有些需要.NET 3.5,但由于3.5仅仅是2.0加上一些其他程序集,因此可能是一个选择...

Briefly searching in google, found this: How to programmatically manipulate Windows 7 shell libraries 在Google中进行简短搜索后发现: 如何以编程方式操作Windows 7 Shell库

if C# examples are not useful, it should be possible to export api methods used in c++ example. 如果C#示例没有用,则应该可以导出c ++示例中使用的api方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM