File Viewer Creation

You can create a file viewer that interacts appropriately with Quick View by following these steps:

  1. Define the file viewer object to use the IPersistFile and IFileViewer interfaces. The object must also implement a separate IUnknown interface that does not delegate calls in aggregation situations. In general, a file viewer object creates or attaches to a window that displays a file's contents.

  2. Implement the Load and GetCurFile member functions (as well as the IUnknown member functions) of the IPersistFile interface. The IsDirty member function can simply return ResultFromScode(S_FALSE) because a file viewer does not modify the file, and the Save and SaveCompleted member functions should simply return ResultFromScode(E_NOTIMPL). Load stores the filename, but delays opening the file until the later call to the IFileViewer::ShowInitialize member function. GetCurFile returns ResultFromScode(E_UNEXPECTED) if Load has not yet been called. Otherwise, it copies the pathname and returns the NOERROR error code.

  3. Implement the IFileViewer::ShowInitialize and IFileViewer::Show member functions (as well as the IUnknown member functions of IFileViewer). ShowInitialize must perform all operations that are prone to failure such that if ShowInitialize succeeds, Show will never fail. The implementation of these two member functions is like an implementation of an application's WinMain function, where ShowInitialize registers window classes (using the instance handle that the DLL receives in its DllEntryPoint function, not the instance of Quick View), creates the necessary windows to meet the UI guidelines, and loads the file as read-only with the path given in IPersistFile::Load. Then Show displays the contents of that file in the viewport window, shows the top-level file viewer window, and enters a message loop. To enhance the appearance of the UI, the file should be loaded and completely displayed in the viewport window before the windows are made visible.

Show does not return until the user has closed the window; that is, Quick View waits for Show to return before terminating. Quick View delegates the responsibility of the message loop to the Show member function, so ShowInitialize and Show look and behave exactly like a WinMain function in any application (the code is just stored in a DLL).

Note that the path in the IPersistFile::Load member function may be a uniform naming convention (UNC) path. Functions such as Win32 OpenFile and OLE StgOpenStorage automatically handle UNC paths. If you open a file any other way, you must be sure to handle UNC paths properly.

  1. Define the class factory object with the IClassFactory interface and implement the interface completely to create a file viewer object. The class factory must support aggregation and server locking, as required by the IClassFactory interface.

  2. Implement the DllGetClassObject function to create an instance of the class factory mentioned in step 4 and return a pointer to one of its interfaces, as required for any component object DLL.

  3. Implement the DllCanUnloadNow function to return the appropriate code, depending on the number of file viewer objects in service and the number of lock counts implemented by using the IClassFactory::LockServer member function, as required for any component object DLL.

  4. Include the Print To feature by using the IFileViewer::PrintTo member function. This step is optional. If this feature is not implemented, the member function must return ResultFromScode(E_NOTIMPL).

  5. Finish the DLL implementation by using the DllEntryPoint function, as required for any Win32-based DLL.

In general, only the implementations of IPersistFile::Load and the IFileViewer member functions are specific to a file viewer. The other steps that deal with creating an OLE component object are standard OLE mechanisms.

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database