9.3 Implementing ICopyHook

only for RuBoard - do not distribute or recompile

9.3 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 a message and return IDNO . All of the parameters to the method are ignored (for now).

Example 9.3. CopyCallback Implementation
 Public Const IDCANCEL = 2 Public Const IDYES = 6 Public Const IDNO = 7 Public Function CopyCallbackA(ByVal this As ICopyHookA, _                                ByVal hwnd As hwnd, _                                ByVal wFunc As UINT, _                                ByVal wFlags As UINT, _                                ByVal pszSrcFile As LPCSTRVB, _                                ByVal dwSrcAttribs As DWORD, _                                ByVal pszDestFile As LPCSTRVB, _                                ByVal dwDestAttribs As DWORD) As Long          MsgBox "Access Denied", vbOKOnly, "CopyCallbackA"     CopyCallbackA = IDNO      End Function Public Function CopyCallbackW(ByVal this As ICopyHookW, _                                ByVal hwnd As hwnd, _                                ByVal wFunc As UINT, _                                ByVal wFlags As UINT, _                                ByVal pszSrcFile As LPCWSTRVB, _                                ByVal dwSrcAttribs As DWORD, _                                ByVal pszDestFile As LPCWSTRVB, _                                ByVal dwDestAttribs As DWORD) As Long     MsgBox "Access Denied", vbOKOnly, "CopyCallbackW"     CopyCallbackW = IDNO      End Function 

We are ready to compile the component. After you finish compiling, all that is left to do is to register the component.

only for RuBoard - do not distribute or recompile


Visual Basic Shell Programming
Visual Basic Shell Programming
ISBN: B00007FY99
EAN: N/A
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net