Step Three: Create the Object Class

Next I created the object I needed, CFileView, by using ClassWizard. The CFileView object is derived from the CCmdTarget class. This class implements the IUnknown interface for you, which means one less thing to do. When I created the class, I selected the OLE Automation and OLE Createable check boxes and gave the class the external name Nancy's Viewer. ClassWizard created the FILEVIEW.CPP and FILEVIEW.H files.

ClassWizard puts a curious line in the CPP file:

IMPLEMENT_OLECREATE(CFileView, "NancyViewer", 0xe83b63c0, 0x6ff5,
0x11ce, 0x99, 0x3c, 0x0, 0xaa, 0x0, 0x4a, 0xdb, 0x6c)

This is a macro that implements class factory support. The class factory allows other applications to create your objects. The numbers listed after the string Nancy's Viewer are combined to create a GUID for the class:

e83b63c0-6ff5-11ce-993c-00aa004adb6c

This line is also included in the VIEWERID.H file, albeit in a somewhat different form:

// ViewerID.H

#ifndef _CLSID_NancyViewer_
#define _CLSID_NancyViewer_

DEFINE_GUID (CLSID_NancyViewer, 0xe83b63c0, 0x6ff5, 0x11ce,
0x99, 0x3c, 0x0, 0xaa, 0x0, 0x4a, 0xdb, 0x6c);

#endif // _CLSID_NancyViewer_