Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
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:
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 15-Nov-11 17:12pm
Edited 28-Nov-11 11:38am
v8
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Have a look at: View Data Your Way With Our Managed Preview Handler Framework[^]
 
Best regards
Espen Harlinn
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 11-Jun-13 19:44pm
   
Good one, a 5.
—SA
Espen Harlinn at 12-Jun-13 15:43pm
   
Thank you, Sergey :-D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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...
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 285
1 DamithSL 265
2 CPallini 195
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 27 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100