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:
#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;
};
const CLASS_OBJECT_INIT c_rgClassObjectInit[] =
{
{ &CLSID_RecipePreviewHandler, CRecipePreviewHandler_CreateInstance }
};
long g_cRefModule = 0;
HINSTANCE g_hInst = NULL;
STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, void *)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
g_hInst = hInstance;
DisableThreadLibraryCalls(hInstance);
}
return TRUE;
}
STDAPI DllCanUnloadNow()
{
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:
HRESULT CRecipePreviewHandler::_CreateStyleSheetNode()
[/modified]
Thanks for all the help,
Andrew