Icon Handler Interfaces

Now that you know how an icon handler works, let’s discuss the interfaces involved in a little more detail.

IPersistFile

IPersistFile inherits one method, GetClassID, from IPersist. IPer-sistFile contains an additional five methods (see Table 5.1): IsDirty, Load, Save, SaveCompleted, and GetCurFile. Typically, IPersistFile is implemented when you want to read or write information from a file. There are many more scenarios. You are encouraged to learn more about this interface, because in the world of COM, this interface gets some major game time. In our case, however, we are only interested in one method, and that’s Load.

We do have a small problem with IPersistFile. It’s derived from IPersist, and VB does not like interfaces that are derived from anything other than IUnknown or IDispatch. This is because Microsoft believes that Visual Basic objects should always support late binding and, hence, should always be derived from IDispatch. So what do we do? Before addressing this question, let’s look at the IDL in Example 5.1, which shows that IPersistFile is derived from IPersist. IPersistFile has inherited the IPersist method GetClassID.

Example 5-1. VB Will Not Accept This Definition of IPersistFile

[ uuid(0000010c-0000-0000-C000-000000000046), helpstring("IPersist Interface"), odl ] interface IPersist : IUnknown { HRESULT GetClassID([in, out] CLSID *lpClassID); } [ uuid(0000010b-0000-0000-C000-000000000046), helpstring("IPersistFile Interface"), odl ] interface ...

Get VB Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.