Click here to Skip to main content
15,881,802 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
I have been upgrading a program from WinXP to Win7 and I would like to take advantage of the ability to preview the contents of the data in saved files. The original data files are images and the file format is custom but they are displayed as bitmaps within my program. In my efforts to learn how to implement the preview functionality I was directed to the MSDN resource for Preview Handlers (and the Recipe Preview Handler) and the example program uses a custom data file *.recipe which is normally not recognized by the preview ability of Win7.

[modified]
There are four files listed in the ReadMe.txt file as belonging to the PreviewHandlerSDKSample project. These are the following:
VB
Files
===============================
RecipePreviewHandler.cpp
PreviewHandlerSDKSample.def
PreviewHandlerSDKSample.vcproj
PreviewHandlerSDKSample.sln

However, there is also a dll.cpp file that is not listed which seems to contain important member definitions for updating the registry. Here is the initial code for that file:
// Copyright (c) Microsoft Corporation. All rights reserved

#include <objbase.h>
#include <shlwapi.h>
#include <new>

extern HRESULT CRecipePreviewHandler_CreateInstance(REFIID riid, void **ppv);

#define SZ_CLSID_RecipePreviewHandler     L"{F654F1BF-54D9-4A2E-B703-889091D3CB2D}"
#define SZ_RECIPEPREVIEWHANDLER           L"Recipe Preview Handler"

const CLSID CLSID_RecipePreviewHandler    = {0xF654F1BF, 0x54D9, 0x4A2E, {0xB7, 0x03, 0x88, 0x90, 0x91, 0xD3, 0xCB, 0x2D}};

typedef HRESULT (*PFNCREATEINSTANCE)(REFIID riid, void **ppvObject);
struct CLASS_OBJECT_INIT
{
    const CLSID *pClsid;
    PFNCREATEINSTANCE pfnCreate;
};

// add classes supported by this module here
const CLASS_OBJECT_INIT c_rgClassObjectInit[] =
{
    { &CLSID_RecipePreviewHandler, CRecipePreviewHandler_CreateInstance }
};


long g_cRefModule = 0;

// Handle the the DLL's module
HINSTANCE g_hInst = NULL;

// Standard DLL functions
STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, void *)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        g_hInst = hInstance;
        DisableThreadLibraryCalls(hInstance);
    }
    return TRUE;
}

STDAPI DllCanUnloadNow()
{
    // Only allow the DLL to be unloaded after all outstanding references have been released
    return (g_cRefModule == 0) ? S_OK : S_FALSE;
}</new></shlwapi.h></objbase.h>

The RecipePreviewHandler.cpp contains the class definition:
C#
class CRecipePreviewHandler : public IObjectWithSite,
                              public IPreviewHandler,
                              public IOleWindow,
                              public IInitializeWithStream

What is the dll.cpp file included in the project? Also, I have tried to start a new project in VS2010 to create my own preview handler, but I am unsure of the configuration. I would like to continue to code in C++ and follow the formula given in the example. Does New Project -- Visual C++ --> Win32 Project --> Application Settings --> dll -->empty project, seem like a suitable project configuration? Finally, the *.recipe preview handler is a disguised *.xml file, but my custom file is saved as a binary file. Can I use the code from my program for opening the file to display my file contents the preview pane or is there a specific format/conversion that I will need? I ask this because there is the following member included in RecipePreviewHandler.cpp:
// Helper method to create an xml node from the an xml string that represents the style-sheet
HRESULT CRecipePreviewHandler::_CreateStyleSheetNode()
[/modified]

Thanks for all the help,
Andrew
Posted
Updated 28-Nov-11 10:38am
v8

Have a look at: View Data Your Way With Our Managed Preview Handler Framework[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Jun-13 19:44pm    
Good one, a 5.
—SA
Espen Harlinn 12-Jun-13 15:43pm    
Thank you, Sergey :-D
the preview handlers are COM objects - so you're best off starting an ATL Project (DLL) and adding a Simple Object to it

You can use BNF[^] to register your DLL (there will already be an RGS file for your object you can augment) - this will automatically get called when you regsvr32.exe your object (this will happen by default on your dev machine at build time, but you'll have to do it yourself/via installer on the client machines)

Create your simple object, inherit from
IObjectWithSite (there is a helper template class IObjectWithSiteImpl<> which may help), IPreviewHandler, IOleWindow and IInitializeWithStream, add them to your interface map using COM_INTERFACE_ENTRY, implement the methods that each itf demands

You're straight in at the deep-end here mate :)
 
Share this answer
 
Have you found the solution for it..i also have to preview an image in preview pane. I dont understand why they have used CreateStyleSheetNode() ??? Could you please send me information on my email id [deleted email] thanks...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900