Welcome to MSDN Blogs Sign in | Join | Help

DllPreviewHandler for Windows Vista

At DevConnections this week, I wanted to demonstrate how easy it can be to write preview handlers for Windows Vista.  Using the framework I created for my article in the January 2007 issue of MSDN Magazine, I whipped up this little guy:

    [PreviewHandler("MSDN Magazine DLL Preview Handler", ".dll", "{1A565B60-5BEA-463d-9413-9F201320A2BB}")]
    [ProgId("MsdnMag.DllPreviewHandler")]
    [Guid("42382862-EFA1-43dc-885A-D02D9B93B320")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComVisible(true)]
    public sealed class DllPreviewHandler : FileBasedPreviewHandler
    {
        protected override PreviewHandlerControl CreatePreviewHandlerControl()
        {
            return new DllPreviewHandlerControl();
        }

        private sealed class DllPreviewHandlerControl : FileBasedPreviewHandlerControl
        {
            public override void Load(FileInfo file)
            {
                TextBox text = new TextBox();
                text.ReadOnly = true;
                text.BackColor = SystemColors.Window;
                text.ScrollBars = ScrollBars.Vertical;
                text.Multiline = true;
                text.Dock = DockStyle.Fill;

                ProcessStartInfo psi = new ProcessStartInfo(
                    @"C:\program files\Microsoft SDKs\Windows\v6.0\VC\Bin\dumpbin.exe",
                    "/summary /exports \"" + file.FullName + "\"");
                psi.UseShellExecute = false;
                psi.RedirectStandardOutput = true;
                psi.CreateNoWindow = true;

                using (Process p = Process.Start(psi))
                {
                    text.Text = p.StandardOutput.ReadToEnd();
                }

                Controls.Add(text);
            }
        }
    }

The preview handler displays the results of running dumpbin.exe on the selected DLL, showing all of the exports from the DLL.  If you do a lot of P/Invoke work, something like this can come in very handy when browsing a directory of DLLs.  To accomplish this, it simply creates a TextBox, spawns a process to run dumpbin, and stuffs the output from dumpbin into the TextBox.

Note that for this to compile and work, you'll need to reference the DLL provided along with the magazine article.  Once you install it, you'll get nice views like this:

On your system, you may need to change the path to dumpbin.exe, which I've hardcoded here for simplicity of example. YMMV.

Published Tuesday, March 27, 2007 10:14 PM by toub
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Friday, March 30, 2007 11:58 AM by Mark

# re: DllPreviewHandler for Windows Vista

Wow, that is amazingly simple.  This is a good thing.  I think we will see some very creative uses of this as Vista matures.  

Is it just as simple to add thumbnail handlers?

Friday, March 30, 2007 6:02 PM by toub

# re: DllPreviewHandler for Windows Vista

Mark, glad you like it! :)  Regarding thumbnail providers, while it is possible to write them in .NET, it's not recommended.  See http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=125283&SiteID=1 for more information.

Friday, April 20, 2007 7:22 PM by J.Marsch

# re: DllPreviewHandler for Windows Vista

Hello:

I've read elsewhere: http://blogs.msdn.com/oldnewthing/archive/2006/12/18/1317290.aspx

that we should not write shell extensions in managed code.  (because it injects a .net runtime version dependency into the shell, and therefore into any application that uses the shell, even when displaying file open/save dialogs).

Does this advice not apply to Vista?

Friday, April 20, 2007 8:09 PM by toub

# re: DllPreviewHandler for Windows Vista

J, please see my article on preview handlers at http://msdn.microsoft.com/msdnmag/issues/07/01/PreviewHandlers/, specifically the section entitled "Hosting a Preview Handler".  That should answer your question.

Friday, June 01, 2007 5:21 AM by Indra

# re: DllPreviewHandler for Windows Vista

Hi,

Is it possible to display the preview in our own application instead of using the explorer??

Friday, June 15, 2007 6:36 AM by Dan

# re: DllPreviewHandler for Windows Vista

Hello,

Is it possible to use Preview Handler within a .Net application rather than accessing explorer to do the preview (aka the new quick preview in Leopard)?

I believe it would be better if it just simply launched a new window showing the preview of the selected file because with the preview pane enabled, it takes up too much desktop estate.

Friday, July 27, 2007 11:30 AM by rpowers

# re: DllPreviewHandler for Windows Vista

It is possible to "host" previews in a managed application.

I just finished some work for the Visual Studio Express team with help from Stephen to build a control and sample of leveraging his managed preview handler framework and displaying the preview results within a .net winform.

The work was part of a bigger project called the coding4fun Developer Kit 2008.  You can get it <a href=http://www.codeplex.com/c4fdevkit>here</a>.  Also I wrote a blog describing the preview handler host <a href=http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/26/3245.aspx>here</a>.

Thanks to Stephen for his help and for building the core framework.

Tuesday, May 13, 2008 9:30 PM by Sreedhar

# re: DllPreviewHandler for Windows Vista

Hi Steve,

I was wondering, if you have come across a solution/utility that would convert audio from WMV files (recorded from live meeting sessions) into a transcript file?

Any insight would be appreciated.

-Sreedhar

Friday, July 24, 2009 3:00 AM by Hou

# re: DllPreviewHandler for Windows Vista

Is this also available for XP OS?

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker