Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. How to make ICopyHook work ?

How to make ICopyHook work ?

Scheduled Pinned Locked Moved COM
c++comtutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khan
    wrote on last edited by
    #1

    I am writing a program which does not let the user copy a specific folder in windows explorer. The way to do this is to implement ICopyHook interface. The dll has been registered at: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shellex\CopyHookHandlers\MyHook I have tried code like this: class ATL_NO_VTABLE CMyHook : public ICopyHook { BEGIN_COM_MAP(CMyHook) COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook , CMyHook) END_COM_MAP() STDMETHOD_(UINT,CopyCallback) (THIS_ HWND hwnd, UINT wFunc, UINT wFlags, LPCSTR pszSrcFile, DWORD dwSrcAttribs, LPCSTR pszDestFile, DWORD dwDestAttribs); }; This function never gets called. Instead when I try to copy a folder, I get the following message: Cannot copy (foldername): Invalid MS-DOS function. What to do? Please F1 !

    K 1 Reply Last reply
    0
    • K khan

      I am writing a program which does not let the user copy a specific folder in windows explorer. The way to do this is to implement ICopyHook interface. The dll has been registered at: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shellex\CopyHookHandlers\MyHook I have tried code like this: class ATL_NO_VTABLE CMyHook : public ICopyHook { BEGIN_COM_MAP(CMyHook) COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook , CMyHook) END_COM_MAP() STDMETHOD_(UINT,CopyCallback) (THIS_ HWND hwnd, UINT wFunc, UINT wFlags, LPCSTR pszSrcFile, DWORD dwSrcAttribs, LPCSTR pszDestFile, DWORD dwDestAttribs); }; This function never gets called. Instead when I try to copy a folder, I get the following message: Cannot copy (foldername): Invalid MS-DOS function. What to do? Please F1 !

      K Offline
      K Offline
      khan
      wrote on last edited by
      #2

      I understood my own code finally. Create a ATLCom Appwizard. Insert a simple atl object. Then add one line: public ICopyHook to the parent list. Comment the other as shown. To the COM_MAP, add one line, comment the others: COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook, CMyHook) class ATL_NO_VTABLE CMyHook : public CComObjectRootEx, public CComCoClass, public ICopyHook // public IDispatchImpl { public: CMyHook() { } DECLARE_REGISTRY_RESOURCEID(IDR_MYHOOK) DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CMyHook) // COM_INTERFACE_ENTRY(IMyHook) // COM_INTERFACE_ENTRY(IDispatch) COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook, CMyHook) END_COM_MAP() STDMETHOD_(UINT,CopyCallback) (THIS_ HWND hwnd, UINT wFunc, UINT wFlags, LPCSTR pszSrcFile, DWORD dwSrcAttribs, LPCSTR pszDestFile, DWORD dwDestAttribs); // IMyHook public: }; The above code works and in the function CopyCallback, you can handle the folder copy event. Of course the registry key also has to be set. Thanks for reading. Hope it works for all.

      J 1 Reply Last reply
      0
      • K khan

        I understood my own code finally. Create a ATLCom Appwizard. Insert a simple atl object. Then add one line: public ICopyHook to the parent list. Comment the other as shown. To the COM_MAP, add one line, comment the others: COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook, CMyHook) class ATL_NO_VTABLE CMyHook : public CComObjectRootEx, public CComCoClass, public ICopyHook // public IDispatchImpl { public: CMyHook() { } DECLARE_REGISTRY_RESOURCEID(IDR_MYHOOK) DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CMyHook) // COM_INTERFACE_ENTRY(IMyHook) // COM_INTERFACE_ENTRY(IDispatch) COM_INTERFACE_ENTRY_IID(IID_IShellCopyHook, CMyHook) END_COM_MAP() STDMETHOD_(UINT,CopyCallback) (THIS_ HWND hwnd, UINT wFunc, UINT wFlags, LPCSTR pszSrcFile, DWORD dwSrcAttribs, LPCSTR pszDestFile, DWORD dwDestAttribs); // IMyHook public: }; The above code works and in the function CopyCallback, you can handle the folder copy event. Of course the registry key also has to be set. Thanks for reading. Hope it works for all.

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        khan++ wrote: I understood my own code finally. That's probably a good thing :-D -- My name in Katakana is ヨルゲン. My name in German is Jörgen. My name in Mandarin/Kanji is 乔尔根 西格瓦德森. My name in Korean is 요르겐. I blog too now[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups