Instantiating COM objects
-
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 anIShellMenuCallback
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 declaresIShellMenuCallback
(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 theIShellMenuCallback
interface? Any help would be much appreciated! -
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 anIShellMenuCallback
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 declaresIShellMenuCallback
(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 theIShellMenuCallback
interface? Any help would be much appreciated!You need to implement the standard IUnknown interface methods: IUnknown::QueryInterface, IUnknown::AddRef, and IUnknown::Release. imo
-
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 anIShellMenuCallback
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 declaresIShellMenuCallback
(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 theIShellMenuCallback
interface? Any help would be much appreciated!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