Creating a Data Handler

We begin the data handler by adding a new class module to the RadEx Project called clsDataHandler. The handler will implement IDataObject and IPersistFile, which have already been defined in the type library from previous chapters. We should add the following code to the general declarations section of clsDataHandler:

'clsDataHandler.cls

Implements IDataObject
Implements IPersistFile

Implementing IPersistFile

The first thing we want to do is implement IPersistFile. Although IPersistFile supports a number of methods (GetCurFile, IsDirty, Load, Save, and SaveCompleted), there is only one method with which we are concerned, Load.

Load

The Load method is implemented exactly as it was in Chapter 5. All we are doing is getting the name of the file being copied, which is passed to the Load method as its pszFileName argument. Example 8.2 shows the code to do this.

Example 8-2. The IPersistFile_Load Method

'clsDataHandler.cls

Implements IDataObject
Implements IPersistFile

Private m_sFile As String

Private Sub IPersistFile_Load(ByVal pszFileName As LPCOLESTR, _ 
    ByVal dwMode As DWORD)

    m_sFile = Space(255)
    CopyMemory ByVal StrPtr(m_sFile), ByVal pszFileName, Len(m_sFile)
 
End Sub

Implementing IDataObject

With that out of the way, we can focus on our IDataObject implementation. Of the nine methods supported by IDataObject, we need to implement just three: QueryGetData, EnumFormatEtc, and GetData.

QueryGetData

The first method we are concerned with is QueryGetData. Remember, ...

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.