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. Instantiating COM objects

Instantiating COM objects

Scheduled Pinned Locked Moved COM
visual-studiocsharpc++comhelp
3 Posts 3 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.
  • U Offline
    U Offline
    User 4649929
    wrote on last edited by
    #1

    Hey guys, I don't know much Windows programming (and my C++ is a little rusty), I'm hoping you all can give me a hand. I'm trying to instantiate an IShellMenu object (http://msdn.microsoft.com/en-us/library/bb774901(VS.85).aspx). MSDN says to create an object I need to: "call CoCreateInstance with the rclsid parameter set to CLSID_MenuBand and the riid parameter set to IID_IShellMenu. You must first initialize the interface by calling IShellMenu::Initialize, and then initialize the menu band by calling IShellMenu::SetShellFolder." The first step is easy enough, I'm doing this:

    IShellMenu *aTest;
    HRESULT aRes = CoCreateInstance(CLSID_MenuBand, NULL, CLSCTX_INPROC_SERVER, IID_IShellMenu, (void **)&aTest);

    But I'm running into trouble when I call aTest->Initialize(). More specifically, the first parameter needs to a pointer to an IShellMenuCallback object and I can't figure out how to instantiate something that implements that interface. Ideally, this is what I'd like to do:

    class CallbackTestImpl1 : public IShellMenuCallback
    {
    public:
    CallbackTestImpl1() { }
    ~CallbackTestImpl1() { }

    // Implement the virtual method
    HRESULT STDMETHODCALLTYPE IShellMenuCallback::CallbackSM(LPSMDATA psmd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
        return S\_OK;
    }
    

    };

    IShellMenu *aTest;
    HRESULT aRes = CoCreateInstance(CLSID_MenuBand, NULL, CLSCTX_INPROC_SERVER, IID_IShellMenu, (void **)&aTest);
    IShellMenuCallback *aCallbackTest = new CallbackTestImpl1();
    aRes = aTest->Initialize(aCallbackTest, -1, ANCESTORDEFAULT, SMINIT_DEFAULT);

    However, Visual Studio complains about my new CallbackTestImpl1() line claiming that it cannot instantiate abstract class. I've looked through the header file that declares IShellMenuCallback (shobjidl.h) and can't find any other methods that I'm not implementing. Am I missing something obvious or is there a better way to instantiate something that implements the IShellMenuCallback interface? Any help would be much appreciated!

    U E 2 Replies Last reply
    0
    • U User 4649929

      Hey guys, I don't know much Windows programming (and my C++ is a little rusty), I'm hoping you all can give me a hand. I'm trying to instantiate an IShellMenu object (http://msdn.microsoft.com/en-us/library/bb774901(VS.85).aspx). MSDN says to create an object I need to: "call CoCreateInstance with the rclsid parameter set to CLSID_MenuBand and the riid parameter set to IID_IShellMenu. You must first initialize the interface by calling IShellMenu::Initialize, and then initialize the menu band by calling IShellMenu::SetShellFolder." The first step is easy enough, I'm doing this:

      IShellMenu *aTest;
      HRESULT aRes = CoCreateInstance(CLSID_MenuBand, NULL, CLSCTX_INPROC_SERVER, IID_IShellMenu, (void **)&aTest);

      But I'm running into trouble when I call aTest->Initialize(). More specifically, the first parameter needs to a pointer to an IShellMenuCallback object and I can't figure out how to instantiate something that implements that interface. Ideally, this is what I'd like to do:

      class CallbackTestImpl1 : public IShellMenuCallback
      {
      public:
      CallbackTestImpl1() { }
      ~CallbackTestImpl1() { }

      // Implement the virtual method
      HRESULT STDMETHODCALLTYPE IShellMenuCallback::CallbackSM(LPSMDATA psmd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
          return S\_OK;
      }
      

      };

      IShellMenu *aTest;
      HRESULT aRes = CoCreateInstance(CLSID_MenuBand, NULL, CLSCTX_INPROC_SERVER, IID_IShellMenu, (void **)&aTest);
      IShellMenuCallback *aCallbackTest = new CallbackTestImpl1();
      aRes = aTest->Initialize(aCallbackTest, -1, ANCESTORDEFAULT, SMINIT_DEFAULT);

      However, Visual Studio complains about my new CallbackTestImpl1() line claiming that it cannot instantiate abstract class. I've looked through the header file that declares IShellMenuCallback (shobjidl.h) and can't find any other methods that I'm not implementing. Am I missing something obvious or is there a better way to instantiate something that implements the IShellMenuCallback interface? Any help would be much appreciated!

      U Offline
      U Offline
      User 697344
      wrote on last edited by
      #2

      You need to implement the standard IUnknown interface methods: IUnknown::QueryInterface, IUnknown::AddRef, and IUnknown::Release. imo

      1 Reply Last reply
      0
      • U User 4649929

        Hey guys, I don't know much Windows programming (and my C++ is a little rusty), I'm hoping you all can give me a hand. I'm trying to instantiate an IShellMenu object (http://msdn.microsoft.com/en-us/library/bb774901(VS.85).aspx). MSDN says to create an object I need to: "call CoCreateInstance with the rclsid parameter set to CLSID_MenuBand and the riid parameter set to IID_IShellMenu. You must first initialize the interface by calling IShellMenu::Initialize, and then initialize the menu band by calling IShellMenu::SetShellFolder." The first step is easy enough, I'm doing this:

        IShellMenu *aTest;
        HRESULT aRes = CoCreateInstance(CLSID_MenuBand, NULL, CLSCTX_INPROC_SERVER, IID_IShellMenu, (void **)&aTest);

        But I'm running into trouble when I call aTest->Initialize(). More specifically, the first parameter needs to a pointer to an IShellMenuCallback object and I can't figure out how to instantiate something that implements that interface. Ideally, this is what I'd like to do:

        class CallbackTestImpl1 : public IShellMenuCallback
        {
        public:
        CallbackTestImpl1() { }
        ~CallbackTestImpl1() { }

        // Implement the virtual method
        HRESULT STDMETHODCALLTYPE IShellMenuCallback::CallbackSM(LPSMDATA psmd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
            return S\_OK;
        }
        

        };

        IShellMenu *aTest;
        HRESULT aRes = CoCreateInstance(CLSID_MenuBand, NULL, CLSCTX_INPROC_SERVER, IID_IShellMenu, (void **)&aTest);
        IShellMenuCallback *aCallbackTest = new CallbackTestImpl1();
        aRes = aTest->Initialize(aCallbackTest, -1, ANCESTORDEFAULT, SMINIT_DEFAULT);

        However, Visual Studio complains about my new CallbackTestImpl1() line claiming that it cannot instantiate abstract class. I've looked through the header file that declares IShellMenuCallback (shobjidl.h) and can't find any other methods that I'm not implementing. Am I missing something obvious or is there a better way to instantiate something that implements the IShellMenuCallback interface? Any help would be much appreciated!

        E Offline
        E Offline
        ekklesia
        wrote on last edited by
        #3

        http://www.codeproject.com/KB/shell/shellextguide1.aspx if you refer to the url which is above , you will find the answer good luck!

        nice to meet u

        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