P / SHELL32与调用,旁路Interop.Shell32.dll代 [英] P/Invoke with Shell32, bypass Interop.Shell32.dll generation

查看:253
本文介绍了P / SHELL32与调用,旁路Interop.Shell32.dll代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用下面的代码来转储每个扩展文件属性来调试控制台...

So I'm using the following code to dump every extended file attribute to the debug console...

ShellClass shellClass = new ShellClass();
Folder dir = shellClass.NameSpace(Path.GetDirectoryName(sFilePath));
FolderItem item = dir.ParseName(Path.GetFileName(sFilePath));
for (int i = 0; i < 267; i++)
{
   System.Debug.WriteLine(dir.GetDetailsOf(item, i));
}



由于SHELL32是一个非托管库,我不能嵌入的DLL资源直接在程序,它有产生一个互操作助手DLL。

As Shell32 is a non-managed library, I can't embed the DLL resource in the program directly, and it has to generate an interop helper DLL.

任何人都知道在SHELL32这些函数的dllimport的命令行来绕过整整一代互操作DLL?我检查pinvoke.net和SHELL32条目下,他们要么没有什么,我在寻找,或者它没有被命名什么,我期待的。

Anyone know of the DLLImport command lines for these functions in Shell32 to get around the whole generation of the interop DLL? I've checked pinvoke.net and under the Shell32 entry they either don't have what I'm looking for, or it's not named what I'm expecting.

如果不是可以使用的DllImport做到这一点,没有人知道的方式使用托管DLL拉所有的扩展属性的有关文件,或至少是一个办法做到这一点,我没有产生助手DLL,并要求与我开发一个应用程序的安装?

If it's not possible to use a DLLImport to accomplish this, does anyone know of a way to pull all of the extended attributes about a file using a managed DLL, or at least a way to do it where I don't have to generate a helper DLL and require an installer with an application I'm developing?

感谢一大堆!

推荐答案

大多数Windows Shell中的API特性具有的p / Invoke入口点返回COM接口,所以你应该很少需要显式创建ShellClass伴生类实例。 (您正在使用的对象,文件夹 FolderItem ,大多意味着使用的后期绑定客户,如脚本语言;用C#你可以做的更好)

Most of the Windows Shell API features have P/Invoke entry points that return COM interfaces, so you should rarely need to explicitly create a ShellClass CoClass instance. (The objects you are using, Folder and FolderItem, are mostly meant for use by late-bound clients such as script languages; with C# you can do much better.)

要避免生成interop程序集,你只需要声明在C#代码的相应类型匹配的。的P / Invoke功能和外壳已经实现COM接口。在你的情况,你要找的是什么的 IShellFolder2 接口(这是对文件夹对象基本上是相同的)。

To avoid having to generate the interop assembly, you just need to declare the appropriate types in your C# code that match the P/Invoke functions and COM interfaces that the shell already implements. In your case, what you're looking for is the IShellFolder2 interface (which is essentially identical to the Folder object).

一般情况下,做你问什么,你会:

Typically, to do what you're asking, you would:


  1. 呼叫< A HREF =http://msdn.microsoft.com/en-us/library/windows/desktop/bb762175%28v=vs.85%29.aspx相对=nofollow> SHGetDesktopFolder 以返回的 的IShellFolder 接口指向桌面文件夹中。

  2. 呼叫的IShellFolder :: ParseDisplayName 上给你一个指针到标识符列表(一个PIDL),表示该文件夹的内壳标识符。

  3. 演员你想要的文件夹,你的的IShellFolder IShellFolder2 (使用,就像任何其他接口)。

  4. 呼叫的 IShellFolder2 :: GetDetailsOf() ,从第2步和你想要的柱子,PIDL。

  1. Call SHGetDesktopFolder to return an IShellFolder interface pointing to the desktop folder.
  2. Call IShellFolder::ParseDisplayName on the folder you want, which gives you a "pointer to an Identifier list" (a PIDL) representing that folder's internal shell identifier.
  3. Cast your IShellFolder to an IShellFolder2 (using as, like any other interfaces).
  4. Call IShellFolder2::GetDetailsOf(), passing the PIDL from step 2 and the column you want.

您将需要两个COM接口翻译,加上一个结构和一个P / Invoke函数,并把C#代码在您的项目。你可以逃脱的IntPtr 对于很多这种(如PIDL),因为你只需要通过他们周围COM方法之间。 (MSDN文章会告诉你,你有责任在完成后释放内存; CLR的互操作的代码会利用这些东西照顾您在几乎所有情况下)。

You will need to translate the two COM interfaces, plus one structure and one P/Invoke function, and put the C# code in your project. You can get away with IntPtr for a lot of this (like the PIDL) since you only need to pass them around between COM methods. (The MSDN articles will tell you that you are responsible for freeing memory after you are done; the CLR's interop code will take care of that stuff for you in almost all cases.)

pinvoke.net将帮助你在这里,因为这会让人着迷写得很好的系列博客文章的做从MSDN文章COM互操作的翻译。

pinvoke.net will help you out here, as will this fascinatingly well written series of blog posts on doing COM interop translations from the MSDN articles.

这篇关于P / SHELL32与调用,旁路Interop.Shell32.dll代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆