O'Reilly logo

VB Shell Programming by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing ICopyHook

Before we begin implementation of ICopyHook, we need to add a new class to the RadEx project called clsCopyHook. The class needs to implement both ICopyHookA and ICopyHookW:

'clsCopyHook.cls

Implements ICopyHookA
Implements ICopyHookW

Also, the address of CopyCallback for both versions of ICopyHook will need to be swapped out in the vtable. We have to do this because CopyCallback will need to return one of three values: IDYES, IDNO, or IDCANCEL. This code, which should be very familiar to you by now, is shown in Example 9.2.

Example 9-2. Class_Initialize Event for Copy Hook Handler

'clsCopyHook.cls

Private m_pOldCopyCallbackA As Long
Private m_pOldCopyCallbackW As Long

Private Sub Class_Initialize(  )
        
    Dim pCopyHookA As ICopyHookA
    Set pCopyHookA = Me
    
    m_pOldCopyCallbackA = SwapVtableEntry( _ 
                          ObjPtr(pCopyHookA), _ 
                          4, _ 
                          AddressOf CopyCallbackA)
    
    Dim pCopyHookW As ICopyHookW
    Set pCopyHookW = Me
    
    m_pOldCopyCallbackW = SwapVtableEntry( _ 
                          ObjPtr(pCopyHookW), _ 
                          4, _ 
                          AddressOf CopyCallbackW)
End Sub

The preceding code is something we’ve seen before.

All that remains now (this is a lie, of course) is to implement CopyCallbackA and CopyCallbackW. For now, our copy hook handler will do nothing but display a message box that says “Access Denied” and then it will return IDNO. Later, we will reimplement the function to display all of the parameters passed in by the shell.

Example 9.3 shows our implementation of CopyCallback. The code is self-explanatory. All it does is display ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required